Switch VMs at bytemark from ntp to systemd-timesyncd
authorPeter Palfrader <peter@palfrader.org>
Fri, 9 Dec 2016 09:27:11 +0000 (09:27 +0000)
committerPeter Palfrader <peter@palfrader.org>
Fri, 9 Dec 2016 09:27:11 +0000 (09:27 +0000)
hieradata/bytemark.yaml
modules/ntp/manifests/init.pp
modules/ntp/manifests/purge.pp [new file with mode: 0644]
modules/systemdtimesyncd/manifests/init.pp [new file with mode: 0644]
modules/systemdtimesyncd/templates/timesyncd.conf.erb [new file with mode: 0644]
modules/time/manifests/init.pp

index cf8caad..739b2b9 100644 (file)
@@ -4,3 +4,7 @@ nameservers:
   - 5.153.231.242
 allow_dns_query:
   - 5.153.231.0/24
+# currently only used by VMs with systemd-timesync
+local-timeservers:
+  - bm-bl1.debian.org
+  - bm-bl2.debian.org
index e180da1..6efd469 100644 (file)
@@ -1,5 +1,4 @@
 class ntp {
-
        package { 'ntp':
                ensure => installed
        }
diff --git a/modules/ntp/manifests/purge.pp b/modules/ntp/manifests/purge.pp
new file mode 100644 (file)
index 0000000..ffe2a11
--- /dev/null
@@ -0,0 +1,44 @@
+class ntp::purge {
+       package { 'ntp':
+               ensure => purged
+       }
+
+       file { '/etc/init.d/ntp':
+               ensure => absent,
+       }
+       file { '/etc/ntp.conf':
+               ensure => absent,
+       }
+       file { '/etc/default/ntp':
+               ensure => absent,
+       }
+
+       file { '/var/lib/ntp':
+               ensure  => absent,
+               recurse => true,
+               purge => true,
+               force => true,
+       }
+       file { '/etc/ntp.keys.d':
+               ensure  => absent,
+               recurse => true,
+               purge => true,
+               force => true,
+       }
+
+       file { '/etc/munin/plugins/ntp_kernel_err':
+               ensure => absent,
+       }
+       file { '/etc/munin/plugins/ntp_offset':
+               ensure => absent,
+       }
+       file { '/etc/munin/plugins/ntp_states':
+               ensure => absent,
+       }
+       file { '/etc/munin/plugins/ntp_kernel_pll_off':
+               ensure => absent,
+       }
+       file { '/etc/munin/plugins/ntp_kernel_pll_freq':
+               ensure => absent,
+       }
+}
diff --git a/modules/systemdtimesyncd/manifests/init.pp b/modules/systemdtimesyncd/manifests/init.pp
new file mode 100644 (file)
index 0000000..6a9a298
--- /dev/null
@@ -0,0 +1,24 @@
+class systemdtimesyncd {
+       $localtimeservers = hiera('local-timeservers', [])
+
+       if (! $systemd) {
+               fail ( "systemdtimesyncd requires systemd." )
+       } elsif (size($localtimeservers) == 0) {
+               fail ( "No local timeservers configured for systemdtimesyncd." )
+       } else {
+               file { '/etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service':
+                               ensure => 'link',
+                               target => '/lib/systemd/system/systemd-timesyncd.service',
+                               notify => Exec['systemctl daemon-reload'],
+               }
+
+               service { 'systemd-timesyncd':
+                       ensure  => running,
+               }
+
+               file { '/etc/systemd/timesyncd.conf':
+                       content => template('systemdtimesyncd/timesyncd.conf.erb'),
+                       notify  => Service['systemd-timesyncd'],
+               }
+       }
+}
diff --git a/modules/systemdtimesyncd/templates/timesyncd.conf.erb b/modules/systemdtimesyncd/templates/timesyncd.conf.erb
new file mode 100644 (file)
index 0000000..c5d41b6
--- /dev/null
@@ -0,0 +1,25 @@
+##
+## THIS FILE IS UNDER PUPPET CONTROL. DON'T EDIT IT HERE.
+## USE: git clone git+ssh://$USER@puppet.debian.org/srv/puppet.debian.org/git/dsa-puppet.git
+##
+
+#  This file is part of systemd.
+#
+#  systemd is free software; you can redistribute it and/or modify it
+#  under the terms of the GNU Lesser General Public License as published by
+#  the Free Software Foundation; either version 2.1 of the License, or
+#  (at your option) any later version.
+#
+# See timesyncd.conf(5) for details
+
+[Time]
+#Servers=0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org
+<%=
+  servers = []
+  localtimeservers.each do |node|
+    scope.lookupvar('site::allnodeinfo')[node]['ipHostNumber'].each do |addr|
+        servers << addr
+    end
+  end
+  "Servers="+servers.join(",")
+%>
index 1dcd5ea..1900443 100644 (file)
@@ -1,4 +1,15 @@
 class time {
-       include ntp
-       include ntpdate
+       include stdlib
+       $localtimeservers = hiera('local-timeservers', [])
+       $physicalHost = $site::allnodeinfo[$fqdn]['physicalHost']
+
+       # if ($::kernel == 'Linux' and $::is_virtual and $::virtual == 'kvm'
+       # our is_virtual and virtual facts are broken
+       if ($systemd and $physicalHost and size($localtimeservers) > 0) {
+               include ntp::purge
+               include systemdtimesyncd
+       } else {
+               include ntp
+               include ntpdate
+       }
 }