Puppet Class: psick::network::hostname

Defined in:
manifests/network/hostname.pp

Summary

This class manages the system hostname

Overview

This class manages the system hostname

Examples:

include psick::network::hostname

Parameters:

  • hostname_file_template (Optional[String]) (defaults to: undef)
  • hostname_legacy (Boolean) (defaults to: false)
  • options (Hash) (defaults to: {})


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'manifests/network/hostname.pp', line 7

class psick::network::hostname (
  Optional[String] $hostname_file_template = undef,
  Boolean          $hostname_legacy        = false,
  Hash             $options                = {},
) {
  $hostname_default_template = $hostname_legacy ? {
    true  => "psick/network/legacy/hostname-${facts['os']['family']}.erb",
    false => "psick/network/hostname-${facts['os']['family']}.erb",
  }
  $file_template = pick($hostname_file_template,$hostname_default_template)
  $manage_hostname = pick($psick::network::hostname,$facts['networking']['fqdn'])

  if $facts['os']['family'] == 'RedHat' {
    file { '/etc/sysconfig/network':
      ensure  => file,
      mode    => '0644',
      owner   => 'root',
      group   => 'root',
      content => template($file_template),
      notify  => $psick::network::manage_config_file_notify,
    }
    case $facts['os']['release']['major'] {
      '7': {
        exec { 'sethostname':
          command => "/usr/bin/hostnamectl set-hostname ${manage_hostname}",
          unless  => "/usr/bin/hostnamectl status | grep 'Static hostname: ${manage_hostname}'",
        }
      }
      default: {}
    }
  }

  if $facts['os']['family'] == 'Debian' {
    file { '/etc/hostname':
      ensure  => file,
      mode    => '0644',
      owner   => 'root',
      group   => 'root',
      content => template($file_template),
      notify  => $psick::network::manage_config_file_notify,
    }
  }

  if $facts['os']['family'] == 'Suse' {
    file { '/etc/HOSTNAME':
      ensure  => file,
      mode    => '0644',
      owner   => 'root',
      group   => 'root',
      content => inline_template("<%= @manage_hostname %>\n"),
      notify  => Exec['sethostname'],
    }
    exec { 'sethostname':
      command => "/bin/hostname ${manage_hostname}",
      unless  => "/bin/hostname -f | grep ${manage_hostname}",
    }
  }

  if $facts['os']['family'] == 'Solaris' {
    file { '/etc/nodename':
      ensure  => file,
      mode    => '0644',
      owner   => 'root',
      group   => 'root',
      content => inline_template("<%= @manage_hostname %>\n"),
      notify  => Exec['sethostname'],
    }
    exec { 'sethostname':
      command => "/usr/bin/hostname ${manage_hostname}",
      unless  => "/usr/bin/hostname | /usr/bin/grep ${manage_hostname}",
    }
  }
}