resolv.conf recipe
Recipe for managing resolv.conf at multiple sites.
Intro
This is a simple recipe for managing resolv.conf at multiple sites. I do a lookup on the 'domain' fact and use this to generate searchpaths and nameservers, which are then used by a template to populate /etc/resolv.conf.
Issues
I'm not sure if this is the best way to go about it - it shifts the configuration for a node out of the node entry and into this class. I was attempting to create a set of classes that could be used to autoconfigure a node without having to explicitly create a node entry, so felt this was a reasonable trade off. There are two obvious ways I see of modifying this further - remove the conditionals and require each node to set or inherit searchpath and nameservers somehow, or else have searchpath and nameservers generated from an external script, which would perhaps be easier to maintain.
Code
class resolvconf {
$searchpath = $domain ? {
'site1.co.nz' => "site1.co.nz",
'site2.co.nz' => "site2.co.nz site2.local",
default => $domain,
}
$nameservers= $domain ? {
'site1' => ['192.168.0.1'],
'site2' => ['10.30.10.1','10.30.10.254'],
default => ['192.168.0.254'],
}
file { "/etc/resolv.conf":
path => "/etc/resolv.conf",
mode => 0644,
owner => root,
group => root,
content => template("/etc/puppet/files/templates/resolv.conf.erb")
}
}
/etc/puppet/files/templates/resolv.conf.erb
search <%= searchpath %> <% nameservers.each do |ns| %>nameserver <%= ns %> <% end %>