I use the IP address to generate a 32bit integer for the server_id for my Mysql configs.
server_id = <%= ipaddress.split('.').inject(0) {|total,value| (total << 8 ) + value.to_i} %> Would something like that work in your case? Ramin On Apr 15, 7:30 am, Rob McBroom <mailingli...@skurfer.com> wrote: > Details below, but the essential problem is this: I need to take a list of > hostnames and assign an integer for each one and ensure that the integer “is > non-negative and is no more than three decimal digits in length”. I’d prefer > that the each hostname lead to the same integer every time. I’ve never > written anything in Ruby before yesterday, so anyone with more experience > have any ideas? > > Boring details: I’m trying to set up replication between LDAP servers. Each > one has to have a unique integer assigned. Details for all of our nodes are > stored in LDAP, so when the template is applied to a node, I can have it get > a list of servers that it should be syncing with by searching for something > like > “(&(classification=ldap)(environment=#{environment})(!(status=inactive*)))”. > > Things I’ve considered so far: > > 1. Just keep a counter as you loop through the list of servers and use that > as the ID. The problem is, if I remove a server from the list (which I am > planning to do soon), the numbers will be reassigned and depending on when > each server checks in with the Puppetmaster, there’s a good chance that two > servers could think they have the same ID. > > 2. Use regex replacements on the hostname. Our hostnames are all in the > format x-xxxx-ldap-01. I could just take the integer part of the name and > then add something to it based on the value of environment, but then I’d have > to assume the hostname format will never change. Political nonsense is common > around here, so I don’t want to rely on that. > > What I really need is something like an MD5 sum of each hostname, but the > resulting numbers are obviously way too big. > > Thanks. > > -- > Rob McBroom > <http://www.skurfer.com/> -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.