<sven.thomas@bt.com>
2009-Jan-15 16:37 UTC
[Puppet Users] Pattern matching in case statement
Hi all, I need my servers to decide which network they are in (i.e. dmz), and the only clue is the servers IP-address. I was trying to accomplish it like this, but it doesn''t work: case $ipaddress { "10.1.1.*": { $network = "net1" } "10.2.2.*.*": { $network = "net2" } "10.3.3.*": { $network = "net3" } } When I change the IP Address to a valid one (like 10.1.1.100) the case works and the network variable is set accordingly. What''s the correct way to do this? Thanks a bunch, Sven --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Robin Lee Powell
2009-Jan-16 23:40 UTC
[Puppet Users] Re: Pattern matching in case statement
On Thu, Jan 15, 2009 at 04:37:53PM -0000, sven.thomas@bt.com wrote:> Hi all, > > > > I need my servers to decide which network they are in (i.e. dmz), and > the only clue is the servers IP-address. I was trying to accomplish it > like this, but it doesn''t work: > > > > case $ipaddress { > > "10.1.1.*": { > > $network = "net1" > > } > > "10.2.2.*.*": {That''s 5 segments. -Robin -- They say: "The first AIs will be built by the military as weapons." And I''m thinking: "Does it even occur to you to try for something other than the default outcome?" -- http://shorl.com/tydruhedufogre http://www.digitalkingdom.org/~rlpowell/ *** http://www.lojban.org/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
<sven.thomas@bt.com>
2009-Jan-19 12:08 UTC
[Puppet Users] Pattern matching in case statement
Hi all, I need my servers to decide which network they are in (i.e. dmz), and the only clue is the servers IP-address. I was trying to accomplish it like this, but it doesn''t work: case $ipaddress { "10.1.1.*": { $network = "net1" } "10.2.2.*.*": { $network = "net2" } "10.3.3.*": { $network = "net3" } } When I change the IP Address to a valid one (like 10.1.1.100) the case works and the network variable is set accordingly. What''s the correct way to do this? Thanks a bunch, Sven --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Am 19.01.2009 um 13:08 schrieb <sven.thomas@bt.com> <sven.thomas@bt.com>:> I need my servers to decide which network they are in (i.e. dmz), > and the only clue is the servers IP-address. I was trying to > accomplish it like this, but it doesn’t work: > > case $ipaddress { > "10.1.1.*": { > $network = "net1" > } > "10.2.2.*.*": { > $network = "net2" > } > "10.3.3.*": { > $network = "net3" > } > } > > When I change the IP Address to a valid one (like 10.1.1.100) the > case works and the network variable is set accordingly. What’s the > correct way to do this?Go with a custom fact, either through an evironment variable on the clients, something like FACTER_NETWORK="net1", which will make a fact called $network available in your manifests, or "true" fact, for which I''d point you to the wiki. Another means would be to write a custom function, which would look somewhat like that (top of my head and not tested at all...): """ module Puppet::Parser::Functions newfunction(:network, :type => :rvalue) do |args| clientip = lookupvar(''ipaddress'') # this assigns $clientip the ipaddress fact of the current client ## Do some clever stuff with clientip, assign $clientnet some value clientnet end end """ The "clever stuff" obviously needs to be some ruby logic, either with nested if/elses or some matches, depending on what you feel most comfortable with. Felix Schäfer --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I just did something similar to parse out what proxy my client should use - for a custom fact do: Facter.add(:network) do setcode do srcIP = Facter.value(:ipaddress) octets = srcIP.split (/\./ ) <logic specific to your use> end end On Jan 19, 7:08 am, <sven.tho...@bt.com> wrote:> Hi all, > > I need my servers to decide which network they are in (i.e. dmz), and > the only clue is the servers IP-address. I was trying to accomplish it > like this, but it doesn''t work: > > case $ipaddress { > > "10.1.1.*": { > > $network = "net1" > > } > > "10.2.2.*.*": { > > $network = "net2" > > } > > "10.3.3.*": { > > $network = "net3" > > } > > } > > When I change the IP Address to a valid one (like 10.1.1.100) the case > works and the network variable is set accordingly. What''s the correct > way to do this? > > Thanks a bunch, > > Sven--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 20 Jan 2009, at 18:52, Jeff Leggett wrote:> > I just did something similar to parse out what proxy my client should > use - for a custom fact do: > > Facter.add(:network) do > setcode do > srcIP = Facter.value(:ipaddress) > octets = srcIP.split (/\./ ) > > <logic specific to your use> > > end > endWe currently use a similar system for establishing settings like resolvers, proxies, and other local-network settings. However, I''m now thinking that using a host-generated fact was not ideal for this purpose - after moving a bunch of servers from one network to another. Essentially, as facter does not report the ipaddress change (and hence network change) until the node is booted with its new IP, the network settings are all wrong until the node can talk to the puppetmaster again - which is likely cannot do as (for example) its resolver settings are pointing to the DNS servers on the old network. For this reason, I''m planning to implement a node-level ''location'' variable, which can be changed manually before a node move, allowing the node to get all its new settings prior to the move. What do others do to solve this problem? Regards, Mike --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Trevor Vaughan
2009-Jan-21 12:19 UTC
[Puppet Users] Re: Pattern matching in case statement
Mike, I would use a server side function that uses either LDAP or a flat file to determine the attributes applied to the node. Although, if you need this to be more ''real time'', you''ll probably want to look at something like ControlTier, Capistrano, or Func. Trevor On Wed, Jan 21, 2009 at 04:37, Mike Pountney <mike.pountney@gmail.com> wrote:> > > On 20 Jan 2009, at 18:52, Jeff Leggett wrote: > >> >> I just did something similar to parse out what proxy my client should >> use - for a custom fact do: >> >> Facter.add(:network) do >> setcode do >> srcIP = Facter.value(:ipaddress) >> octets = srcIP.split (/\./ ) >> >> <logic specific to your use> >> >> end >> end > > > We currently use a similar system for establishing settings like > resolvers, proxies, and other local-network settings. > > However, I''m now thinking that using a host-generated fact was not > ideal for this purpose - after moving a bunch of servers from one > network to another. > > Essentially, as facter does not report the ipaddress change (and hence > network change) until the node is booted with its new IP, the network > settings are all wrong until the node can talk to the puppetmaster > again - which is likely cannot do as (for example) its resolver > settings are pointing to the DNS servers on the old network. > > For this reason, I''m planning to implement a node-level ''location'' > variable, which can be changed manually before a node move, allowing > the node to get all its new settings prior to the move. > > What do others do to solve this problem? > > Regards, > > Mike > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
<sven.thomas@bt.com>
2009-Jan-21 14:58 UTC
[Puppet Users] Re: Pattern matching in case statement
Thank you for your input! I solved it like this in then end: Facter.add("netenv") do setcode do begin Facter.ipaddress rescue Facter.loadfacts() end distid = Facter.value(''ipaddress'') if distid.match(/10.1.1.|172./) network = "net1" elsif distid.match(/10.2.2./) network = "net2" elsif distid.match(/10.3.3./) network = "dmz" else network = "unknown" end network end end Sven -----Original Message----- From: puppet-users@googlegroups.com [mailto:puppet-users@googlegroups.com] On Behalf Of Jeff Leggett Sent: Tuesday, January 20, 2009 7:52 PM To: Puppet Users Subject: [Puppet Users] Re: Pattern matching in case statement I just did something similar to parse out what proxy my client should use - for a custom fact do: Facter.add(:network) do setcode do srcIP = Facter.value(:ipaddress) octets = srcIP.split (/\./ ) <logic specific to your use> end end On Jan 19, 7:08 am, <sven.tho...@bt.com> wrote:> Hi all, > > I need my servers to decide which network they are in (i.e. dmz), and > the only clue is the servers IP-address. I was trying to accomplish it > like this, but it doesn''t work: > > case $ipaddress { > > "10.1.1.*": { > > $network = "net1" > > } > > "10.2.2.*.*": { > > $network = "net2" > > } > > "10.3.3.*": { > > $network = "net3" > > } > > } > > When I change the IP Address to a valid one (like 10.1.1.100) the case > works and the network variable is set accordingly. What''s the correct > way to do this? > > Thanks a bunch, > > Sven--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jeffrey Hulten
2009-Jan-21 23:15 UTC
[Puppet Users] Re: Pattern matching in case statement
If I understand the match function on strings properly you might want to escape the periods in your logic: 10.1.1. matches 10.1.1.X and 10.101.X for instance. On Wed, Jan 21, 2009 at 6:58 AM, <sven.thomas@bt.com> wrote:> > Thank you for your input! I solved it like this in then end: > > Facter.add("netenv") do > setcode do > begin > Facter.ipaddress > rescue > Facter.loadfacts() > end > distid = Facter.value(''ipaddress'') > if distid.match(/10.1.1.|172./) > network = "net1" > elsif distid.match(/10.2.2./) > network = "net2" > elsif distid.match(/10.3.3./) > network = "dmz" > else > network = "unknown" > end > network > end > end > > > Sven > > -----Original Message----- > From: puppet-users@googlegroups.com [mailto:puppet-users@googlegroups.com] On Behalf Of Jeff Leggett > Sent: Tuesday, January 20, 2009 7:52 PM > To: Puppet Users > Subject: [Puppet Users] Re: Pattern matching in case statement > > > I just did something similar to parse out what proxy my client should > use - for a custom fact do: > > Facter.add(:network) do > setcode do > srcIP = Facter.value(:ipaddress) > octets = srcIP.split (/\./ ) > > <logic specific to your use> > > end > end > > On Jan 19, 7:08 am, <sven.tho...@bt.com> wrote: >> Hi all, >> >> I need my servers to decide which network they are in (i.e. dmz), and >> the only clue is the servers IP-address. I was trying to accomplish it >> like this, but it doesn''t work: >> >> case $ipaddress { >> >> "10.1.1.*": { >> >> $network = "net1" >> >> } >> >> "10.2.2.*.*": { >> >> $network = "net2" >> >> } >> >> "10.3.3.*": { >> >> $network = "net3" >> >> } >> >> } >> >> When I change the IP Address to a valid one (like 10.1.1.100) the case >> works and the network variable is set accordingly. What''s the correct >> way to do this? >> >> Thanks a bunch, >> >> Sven > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---