A collection of task oriented solutions in Puppet

 

Adding a per-domain hostname

Challenge

In certain network architectures you have roles defined that are implemented on a number of machines in different domains. A local package mirror, a syslog forwarding host and a local network time servers are all examples of this. You need a host entry that points to a different ip address depending on the location of the client.

Solution

class per_domain_ips {

  host { 'syslog':
    ip => $::domain ? {
        /production/ => '10.10.10.10',
        /staging/    => '192.168.23.10',
        default      => '10.100.100.100',
    }
  }

}

Explanation

Using a combination of whichever fact best describes your clients location (we're using the domain part of the hostname in the example above) and a selector you can choose the correct IP address for your local version of which ever machine you're dealing with.

While most lookups of this type should live in DNS sometimes there are a handful of services that are important enough to have their host/ip mappings configured on the servers themselves. By using this approach you can localise where possible while always having the 'default' entries IP address as the common fall back.

See also