From: Peter Palfrader Date: Fri, 9 Dec 2016 09:27:11 +0000 (+0000) Subject: Switch VMs at bytemark from ntp to systemd-timesyncd X-Git-Url: https://git.adam-barratt.org.uk/?a=commitdiff_plain;h=0faf9685026413c4b14bc2baa512b27f51b3d65d;p=mirror%2Fdsa-puppet.git Switch VMs at bytemark from ntp to systemd-timesyncd --- diff --git a/hieradata/bytemark.yaml b/hieradata/bytemark.yaml index cf8caad8e..739b2b9df 100644 --- a/hieradata/bytemark.yaml +++ b/hieradata/bytemark.yaml @@ -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 diff --git a/modules/ntp/manifests/init.pp b/modules/ntp/manifests/init.pp index e180da195..6efd46984 100644 --- a/modules/ntp/manifests/init.pp +++ b/modules/ntp/manifests/init.pp @@ -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 index 000000000..ffe2a11cf --- /dev/null +++ b/modules/ntp/manifests/purge.pp @@ -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 index 000000000..6a9a298a5 --- /dev/null +++ b/modules/systemdtimesyncd/manifests/init.pp @@ -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 index 000000000..c5d41b6ba --- /dev/null +++ b/modules/systemdtimesyncd/templates/timesyncd.conf.erb @@ -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(",") +%> diff --git a/modules/time/manifests/init.pp b/modules/time/manifests/init.pp index 1dcd5ead9..1900443fd 100644 --- a/modules/time/manifests/init.pp +++ b/modules/time/manifests/init.pp @@ -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 + } }