diff options
Diffstat (limited to 'lib/puppet/parser/functions/fqdn_rand.rb')
-rw-r--r-- | lib/puppet/parser/functions/fqdn_rand.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions/fqdn_rand.rb b/lib/puppet/parser/functions/fqdn_rand.rb new file mode 100644 index 000000000..2ae46de82 --- /dev/null +++ b/lib/puppet/parser/functions/fqdn_rand.rb @@ -0,0 +1,15 @@ +Puppet::Parser::Functions::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 |