Puppet Class: systemd::timesyncd

Defined in:
manifests/timesyncd.pp

Overview

This class provides an abstract way to trigger systemd-timesyncd

Parameters:

  • ensure (Enum['stopped','running']) (defaults to: $systemd::timesyncd_ensure)

    The state that the “networkd“ service should be in

  • ntp_server (Optional[Variant[Array,String]]) (defaults to: $systemd::ntp_server)

    A space-separated list of NTP servers, will be combined with interface specific addresses from systemd-networkd. requires puppetlabs-inifile

  • fallback_ntp_server (Optional[Variant[Array,String]]) (defaults to: $systemd::fallback_ntp_server)

    A space-separated list of NTP server host names or IP addresses to be used as the fallback NTP servers. Any per-interface NTP servers obtained from systemd-networkd take precedence over this setting. requires puppetlabs-inifile



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
# File 'manifests/timesyncd.pp', line 16

class systemd::timesyncd (
  Enum['stopped','running'] $ensure                    = $systemd::timesyncd_ensure,
  Optional[Variant[Array,String]] $ntp_server          = $systemd::ntp_server,
  Optional[Variant[Array,String]] $fallback_ntp_server = $systemd::fallback_ntp_server,
) {
  assert_private()

  $_enable_timesyncd = $ensure ? {
    'stopped' => false,
    'running' => true,
    default   => $ensure,
  }

  service { 'systemd-timesyncd':
    ensure => $ensure,
    enable => $_enable_timesyncd,
  }

  if $ntp_server {
    if $ntp_server =~ String {
      $_ntp_server = $ntp_server
    } else {
      $_ntp_server = join($ntp_server, ' ')
    }
    ini_setting { 'ntp_server':
      ensure  => 'present',
      value   => $_ntp_server,
      setting => 'NTP',
      section => 'Time',
      path    => '/etc/systemd/timesyncd.conf',
      notify  => Service['systemd-timesyncd'],
    }
  }

  if $fallback_ntp_server {
    if $fallback_ntp_server =~ String {
      $_fallback_ntp_server = $fallback_ntp_server
    } else {
      $_fallback_ntp_server = join($fallback_ntp_server, ' ')
    }
    ini_setting { 'fallback_ntp_server':
      ensure  => 'present',
      value   => $_fallback_ntp_server,
      setting => 'FallbackNTP',
      section => 'Time',
      path    => '/etc/systemd/timesyncd.conf',
      notify  => Service['systemd-timesyncd'],
    }
  }
}