ForumUser
2013-Apr-12 08:44 UTC
[Puppet Users] How to setup /etc/resolv.conf dependent on network
Hello, I am a beginner in puppet so please excuse my lack of knowledge. (I use puppet 3.1). We have nodes in different networks - they use different DNS servers. I''d like to set up its /etc/resolv.conf dependent on network they are in. What approach would you recommend to solve the problem ? Thanks in advance Przemek -- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Josh
2013-Apr-12 09:09 UTC
[Puppet Users] Re: How to setup /etc/resolv.conf dependent on network
On Friday, April 12, 2013 9:44:31 AM UTC+1, ForumUser wrote:> We have nodes in different networks - they use different DNS servers. > I''d like to set up its /etc/resolv.conf dependent on network they are in. >Are you using Hiera? We run multiple datacentres that have different management networks, syslog servers and such, I provide the server with knowledge of the datacentre with a custom fact (which just reads a file in my case) and then in the hiera config I have: :hierarchy: - nodes/%{hostname} - common/%{datacentre} Then anything specific to the datacentre goes in that file. You could easily do something similar for the network. Alternatively you might be able to define it all in a case statement matching the IP address of the server, although depending on how complicated your network architecture the regexs could become complicated: case $::ipaddress_eth0 { /^192.168.1/: { $nameserver = ''192.168.1.254'' } /^192.168.2/: { $nameserver = ''192.168.2.254'' } } Josh -- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
ForumUser
2013-Apr-12 09:37 UTC
[Puppet Users] Re: How to setup /etc/resolv.conf dependent on network
We are not using Hiera yet (but it seems that this is what we should do in the close future ...) At the moment the regexp expression is the simplest one. Thank you :-) On Friday, 12 April 2013 10:09:00 UTC+1, Josh wrote:> > On Friday, April 12, 2013 9:44:31 AM UTC+1, ForumUser wrote: > >> We have nodes in different networks - they use different DNS servers. >> I''d like to set up its /etc/resolv.conf dependent on network they are in. >> > > Are you using Hiera? We run multiple datacentres that have different > management networks, syslog servers and such, I provide the server with > knowledge of the datacentre with a custom fact (which just reads a file in > my case) and then in the hiera config I have: > > :hierarchy: > - nodes/%{hostname} > - common/%{datacentre} > > Then anything specific to the datacentre goes in that file. You could > easily do something similar for the network. > > Alternatively you might be able to define it all in a case statement > matching the IP address of the server, although depending on how > complicated your network architecture the regexs could become complicated: > > case $::ipaddress_eth0 { > /^192.168.1/: { $nameserver = ''192.168.1.254'' } > /^192.168.2/: { $nameserver = ''192.168.2.254'' } > } > > Josh >-- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
ForumUser
2013-Apr-12 14:54 UTC
[Puppet Users] Re: How to setup /etc/resolv.conf dependent on network
Josh, what if I have 192.168.* with exception of 192.168.100.* ? Is the order in case statement important ? E.g.: case $::ipaddress_eth0 { /^192.168.100/: { $nameserver = ''192.168.100.254'' } /^192.168./: { $nameserver = ''192.168.1.254'' } } On Friday, 12 April 2013 10:09:00 UTC+1, Josh wrote:> > On Friday, April 12, 2013 9:44:31 AM UTC+1, ForumUser wrote: > >> We have nodes in different networks - they use different DNS servers. >> I''d like to set up its /etc/resolv.conf dependent on network they are in. >> > > Are you using Hiera? We run multiple datacentres that have different > management networks, syslog servers and such, I provide the server with > knowledge of the datacentre with a custom fact (which just reads a file in > my case) and then in the hiera config I have: > > :hierarchy: > - nodes/%{hostname} > - common/%{datacentre} > > Then anything specific to the datacentre goes in that file. You could > easily do something similar for the network. > > Alternatively you might be able to define it all in a case statement > matching the IP address of the server, although depending on how > complicated your network architecture the regexs could become complicated: > > case $::ipaddress_eth0 { > /^192.168.1/: { $nameserver = ''192.168.1.254'' } > /^192.168.2/: { $nameserver = ''192.168.2.254'' } > } > > Josh >-- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Josh
2013-Apr-12 15:29 UTC
[Puppet Users] Re: How to setup /etc/resolv.conf dependent on network
On Friday, April 12, 2013 3:54:16 PM UTC+1, ForumUser wrote:> > what if I have 192.168.* with exception of 192.168.100.* ? > Is the order in case statement important ? > E.g.: > > case $::ipaddress_eth0 { > /^192.168.100/: { $nameserver = ''192.168.100.254'' } > /^192.168./: { $nameserver = ''192.168.1.254'' } > } >It will choose the first match in the case statement. You can also add a default (and I would always have a default anyway, even if it is just to fail with a sensible message) case $::ipaddress_eth0 { /^192.168.100/: { $nameserver = ''192.168.100.254'' } /^192.168./: { $nameserver = ''192.168.1.254'' } default: { fail("You shouldn''t get this far") } } -- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Jakov Sosic
2013-Jul-01 16:53 UTC
Re: [Puppet Users] How to setup /etc/resolv.conf dependent on network
On 04/12/2013 10:44 AM, ForumUser wrote:> Hello, > > I am a beginner in puppet so please excuse my lack of knowledge. > (I use puppet 3.1). > > We have nodes in different networks - they use different DNS servers. > I''d like to set up its /etc/resolv.conf dependent on network they are in. > > What approach would you recommend to solve the problem ?Use facts about your network, like ip_address and netmask, and calculate nameservers from that info: $ facter -p | egrep "^(ipaddress |netmask )" ipaddress => 192.168.0.164 netmask => 255.255.255.0 -- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.