summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorJames Turnbull <james@lovedthanlost.net>2008-05-22 17:10:30 +1000
committerJames Turnbull <james@lovedthanlost.net>2008-05-22 17:10:30 +1000
commitd54338f8921b4b2973dcde52576d7e9fa58148cb (patch)
tree977d650cb3d23dba1ae45979525589e0e2b54279 /lib/puppet
parent6ea494f383ab51b14238e0b8dcb8925d3faa6c83 (diff)
downloadpuppet-d54338f8921b4b2973dcde52576d7e9fa58148cb.tar.gz
puppet-d54338f8921b4b2973dcde52576d7e9fa58148cb.tar.xz
puppet-d54338f8921b4b2973dcde52576d7e9fa58148cb.zip
Added cron random function fixing ticket #311
Diffstat (limited to 'lib/puppet')
-rwxr-xr-xlib/puppet/type/cron.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb
index c46a7c83b..9f1e7c42c 100755
--- a/lib/puppet/type/cron.rb
+++ b/lib/puppet/type/cron.rb
@@ -390,6 +390,21 @@ Puppet::Type.newtype(:cron) do
}
end
+ newfunction(:fqdn_rand, :type => :rvalue, :doc => "Generates random numbers
+ based on the node's fqdn. The first argument sets the range. The second
+ argument specifies a number to add to the seed and is optional.") do |args|
+ require 'md5'
+ max = args[0]
+ if args[1] then
+ seed = args[1]
+ else
+ seed = 1
+ end
+ fqdn_seed = MD5.new(lookupvar('fqdn')).to_s.hex
+ srand(seed+fqdn_seed)
+ rand(max).to_s
+ end
+
# We have to reorder things so that :provide is before :target
attr_accessor :uid