Puppet Class: ntp::config

Defined in:
manifests/config.pp

Summary

This class handles the configuration file.

Overview



6
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'manifests/config.pp', line 6

class ntp::config {

  #The servers-netconfig file overrides NTP config on SLES 12, interfering with our configuration.
  if ($facts['operatingsystem'] == 'SLES' and $facts['operatingsystemmajrelease'] == '12') or
    ($facts['operatingsystem'] == 'OpenSuSE' and $facts['operatingsystemmajrelease'] == '42') {
    file { '/var/run/ntp/servers-netconfig':
      ensure => 'absent'
    }
  }

  case $::osfamily
  {
    'redhat':
    {
      $daemon_config = '/etc/sysconfig/ntpd'
      if $ntp::daemon_extra_opts {
        file_line { 'Set NTPD daemon options':
          ensure => present,
          path   => $daemon_config,
          line   => "OPTIONS='${ntp::daemon_extra_opts}'",
          match  => '^OPTIONS\=',
        }
      }
      if $ntp::user and $facts['operatingsystemmajrelease'] != '6' {
        file_line { 'Set NTPD daemon user':
          ensure => present,
          path   => '/etc/systemd/system/multi-user.target.wants/ntpd.service',
          line   => "ExecStart=/usr/sbin/ntpd -u ${ntp::user}:${ntp::user} \$OPTIONS",
          match  => '^ExecStart\=',
        }
      }
    }
    'Debian':
    {
      $daemon_config = '/etc/default/ntp'
      if $ntp::daemon_extra_opts {
        file_line { 'Set NTPD daemon options':
          ensure => present,
          path   => $daemon_config,
          line   => "NTPD_OPTS='${ntp::daemon_extra_opts}'",
          match  => '^NTPD_OPTS\=',
        }
      }
      if $ntp::user and $facts['operatingsystemmajrelease'] == '18.04' {
        file_line { 'Set NTPD daemon user':
          ensure => present,
          path   => '/usr/lib/ntp/ntp-systemd-wrapper',
          line   => "RUNASUSER=${ntp::user}",
          match  => '^RUNASUSER\=',
        }
      }
    }
    'Suse':
    {
      $daemon_config = '/etc/sysconfig/ntp'
      if $ntp::daemon_extra_opts {
        file_line { 'Set NTPD daemon options':
          ensure => present,
          path   => $daemon_config,
          line   => "OPTIONS='${ntp::daemon_extra_opts}'",
          match  => '^OPTIONS\=',
        }
      }
    }
    default: { }
  }

  if $ntp::keys_enable {
    case $ntp::config_dir {
      '/', '/etc', undef: {}
      default: {
        file { $ntp::config_dir:
          ensure  => directory,
          owner   => 0,
          group   => 0,
          mode    => '0775',
          recurse => false,
        }
      }
    }

    file { $ntp::keys_file:
      ensure  => file,
      owner   => 0,
      group   => 0,
      mode    => '0600',
      content => epp('ntp/keys.epp'),
    }
  }

  #If both epp and erb are defined, throw validation error.
  #Otherwise use the defined erb/epp template, or use default
  if $ntp::config_epp and $ntp::config_template {
    fail('Cannot supply both config_epp and config_template templates for ntp config file.')
  } elsif $ntp::config_template {
    $config_content = template($ntp::config_template)
  } elsif $ntp::config_epp {
    $config_content = epp($ntp::config_epp)
  } else {
    $config_content = epp('ntp/ntp.conf.epp')
  }

  file { $ntp::config:
    ensure  => file,
    owner   => 0,
    group   => 0,
    mode    => $::ntp::config_file_mode,
    content => $config_content,
  }

  #If both epp and erb are defined, throw validation error.
  #Otherwise use the defined erb/epp template, or use default

  if $::ntp::step_tickers_file {
    if $::ntp::step_tickers_template and $::ntp::step_tickers_epp {
      fail('Cannot supply both step_tickers_file and step_tickers_epp templates for step ticker file')
    } elsif $::ntp::step_tickers_template {
      $step_ticker_content = template($ntp::step_tickers_template)
    } elsif $::ntp::step_tickers_epp {
      $step_ticker_content = epp($::ntp::step_tickers_epp)
    } else{
      $step_ticker_content = epp('ntp/step-tickers.epp')
    }

    file { $::ntp::step_tickers_file:
      ensure  => file,
      owner   => 0,
      group   => 0,
      mode    => $::ntp::config_file_mode,
      content => $step_ticker_content,
    }
  }

  if $ntp::logfile {
    file { $ntp::logfile:
      ensure => file,
      owner  => $ntp::logfile_user,
      group  => $ntp::logfile_group,
      mode   => $ntp::logfile_mode,
    }
  }

  if $ntp::disable_dhclient {
    augeas { 'disable ntp-servers in dhclient.conf':
      context => '/files/etc/dhcp/dhclient.conf',
      changes => 'rm request/*[.="ntp-servers"]',
    }

    file { '/var/lib/ntp/ntp.conf.dhcp':
      ensure => absent,
    }

    #remove dhclient ntp script which modifies ntp.conf on RHEL and Amazon Linux
    file { '/etc/dhcp/dhclient.d/ntp.sh':
      ensure => absent,
    }
  }
}