My custom puppet code changes values randomly. Why?
This code creates a random port for me based on the argument's hash. The idea is that this will create a TCP port for me based on the name of the argument I give it (for instance the FQDN) so that it is unique, above 1024 but below 65535. I don't want to have to worry about port numbers, it should just calculate the same every time.
module Puppet::Parser::Functions
newfunction(:ip_port, :type => :rvalue) do |args|
args[0].hash % 64511 + 1024
end
end
I use it in a manifest this way:
The puppet agent runs every 30 minutes by default. It's a master/slave v3.8 setup. When I run it manually, the value always comes back the same. But when I leave it alone, at some point the value changes. I use this to create ports for haproxy. Thanks for your help.