Hi Everyone,

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:
$ip_port = ip_port('www.example.com')

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.


Peter

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/d2551534-236d-4598-b288-1faa7d3c6bb0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to