Puppet: System Administration Automated

Puppet Training Schedule
Next Class July 27-29
New York, New York
Discount before July 1st

resolv.conf recipe

Recipe for managing resolv.conf on Solaris (and Linux).

Intro

I enhanced the original recipe and built this as a module. I think this recipe is more complete as it now makes "search" entries optional. It also separates the logic from your config class(es).

Issues

The resolver "Class" body is essentially empty. I left it there for filler since the code can potentially evolve into a more complex beast.

Code

/etc/puppet/modules/resolver/manifests/init.pp:

# Class: resolver
#
# This class handles configuring /etc/resolv.conf
#
# Parameters:
#       $domainname: The default domain
#
#       $searchpath: Array of domains to search
#
#       $nameservers: List of nameservers to search
#
# Actions:
#       Configures the /etc/resolv.conf file according to parameters
#
# Requires:
#
# Sample Usage:
#       resolv_conf { "example":
#                       domainname  => "mydomain",
#                       searchpath  => ['mydomain', 'test.mydomain'],
#                       nameservers => ['192.168.1.100', '192.168.1.101', '192.168.1.102'],
#       }
#
class resolver {
        # noop
}

define resolv_conf($domainname = "$domain", $searchpath, $nameservers) {
        file { "/etc/resolv.conf":
                owner   => root,
                group   => root,
                mode    => 644,
                content => template("resolver/resolv.conf.erb"),
        }
}

/etc/puppet/modules/resolver/templates/resolv.conf.erb:

domain <%= domainname %>
<% if !searchpath.empty? %>search <%= searchpath.join(" ") %>
<% end -%>
<% nameservers.each do |ns| %>nameserver <%= ns %>
<% end -%>

Example Usage

/etc/puppet/manifests/nodes.pp:

node 'testnode': {
  import "resolver"

  resolv_conf { "example":
                  domainname  => "mydomain",
                  searchpath  => ['mydomain', 'test.mydomain'],
                  nameservers => ['192.168.1.100', '192.168.1.101', '192.168.1.102'],
  }
}