Henry
2008-Jul-17 14:31 UTC
[Puppet Users] deriving a site variable based on clients primary IP address
I''ve written a custom facter script that works out which class network range a machine is on (apologies for the rubbish ruby scripting but it does the job for the time being). Facter.add("ipaddress_range") do setcode do %x{facter ipaddress | awk -F"." ''{print $1"."$2"."$3}''}.chomp end end I''m then using this to define local resources they should use (eg. mailhost/DNS/NTP/build, etc...) by the following class. class util { # define list of class c networks associated with each site $sitea_ipaddress_ranges = [ "192.168.1", "192.168.2", "192.168.3" ] $siteb_ipaddress_ranges = [ "192.168.4", "192.168.5", "192.168.6" ] # work out location based on ipaddress_range fact and list of networks above case $ipaddress_range { $sitea_ipaddress_ranges : { $location = "sitea" } $siteb_ipaddress_ranges: { $location = "siteb" } default : { $location "sitea" } } # work out build server and location of yum repos based on location $buildserver = $location ? { ''sitea'' => "build0", ''siteb'' => "build1", default => "build0" } } I think my syntax for the case statement is wrong - I''ve used a variable because there are potentially numerous address ranges and its easier just to have a couple of long lists rather than continually adding to the case statement. Any suggestions greatfully appreciated! Rgds, Henry --~--~---------~--~----~------------~-------~--~----~ 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-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Scott Smith
2008-Jul-17 16:54 UTC
[Puppet Users] Re: deriving a site variable based on clients primary IP address
Henry wrote:> I''ve written a custom facter script that works out which class network > range a machine is on (apologies for the rubbish ruby scripting but it > does the job for the time being). > > Facter.add("ipaddress_range") do > setcode do > %x{facter ipaddress | awk -F"." ''{print $1"."$2"."$3}''}.chomp > end > endI would advise against hard coding such an expectation of an IP address being part of a /24. I personally had to do something similar but instead designed a SQL back end which had a table listing various machine/app types. It was super trivial at that point to map their relationships to a puppet node manifest. This gives you complete dynamicity (??WTF??) of machines regardless of their state or network location. -scott --~--~---------~--~----~------------~-------~--~----~ 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-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Mike Renfro
2008-Jul-17 17:00 UTC
[Puppet Users] Re: deriving a site variable based on clients primary IP address
On 7/17/2008 11:54 AM, Scott Smith wrote:> I personally had to do something similar but instead designed a SQL back > end which had a table listing various machine/app types. It was super > trivial at that point to map their relationships to a puppet node manifest.One could possibly adapt http://reductivelabs.com/trac/puppet/wiki/Recipes/HostgroupFact , as well. -- Mike Renfro / R&D Engineer, Center for Manufacturing Research, 931 372-3601 / Tennessee Technological University --~--~---------~--~----~------------~-------~--~----~ 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-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---