A collection of task oriented solutions in Puppet


Adding a per-domain hostname


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.


class per_domain_ips {

  $ip = $::domain ? {
          /production/ => '',
          /staging/    => '',
          default      => '',

  host { 'syslog':
    ip => $ip,



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 whichever 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 fallback.

See also