Thanks, Trevor. I did and as you had predicted they are different. On Wednesday, May 18, 2016 at 7:35:55 AM UTC-7, Trevor Vaughan wrote: > > Hi Peter, > > Object.hash in Ruby provides the hash of the Object ID, not a consistent > cryptographic hash of the string provided. > > Try it in two different IRB sessions and you'll see what I mean. It will > change between garbage collection runs and/or at every invocation of Puppet > if done in cron. > > Trevor > > > > On Tue, May 17, 2016 at 7:42 PM, p <[email protected] <javascript:>> wrote: > >> 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] <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/puppet-users/d2551534-236d-4598-b288-1faa7d3c6bb0%40googlegroups.com >> >> <https://groups.google.com/d/msgid/puppet-users/d2551534-236d-4598-b288-1faa7d3c6bb0%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Trevor Vaughan > Vice President, Onyx Point, Inc > (410) 541-6699 x788 > > -- This account not approved for unencrypted proprietary information -- >
-- 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/9dbee805-57c9-4098-ae08-d1d30947ae87%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
