Puppet Class: r_profile::linux::hostname

Defined in:
manifests/linux/hostname.pp

Overview

R_profile::Linux::Hostname

Set the hostname using systemd and optionally the system IP address. By default, set the hostname to match ‘certname` - the name of the signed certificate that puppet knows about. This is useful for cloud environments such as azure that assign dnsdomains based on regions that cannot be changed to a sensible default

Examples:

Set the hostname based on the puppet ‘certname`

include r_profile::linux::hostname

Parameters:

  • fqdn (String) (defaults to: hiera("r_profile::linux::hostname::fqdn", $trusted['certname']))

    The fully qualified hostname that this host should use for all names

  • ip (Optional[String]) (defaults to: hiera("r_profile::linux::hostname::ip", undef))

    The IP address of a corresponding entry to add to /etc/hosts if required



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'manifests/linux/hostname.pp', line 14

class r_profile::linux::hostname(
    String            $fqdn = hiera("r_profile::linux::hostname::fqdn", $trusted['certname']),
    Optional[String]  $ip   = hiera("r_profile::linux::hostname::ip", undef),
) {

  if $fqdn {

    exec { "set hostname to ${fqdn}":
      command  => "hostnamectl set-hostname ${fqdn}",
      unless   => "[[ \"$(hostnamectl status --static)\" == ${fqdn} ]]",
      path     => ['/usr/bin/', '/bin'],
      provider => shell,
    }

    if $ip {
      host { $fqdn:
        ensure => present,
        ip     => $ip,
      }
    }
  }
}