From e75b11402c66d94c85f9f344aafca9c939a48852 Mon Sep 17 00:00:00 2001 From: Ossi Salmi Date: Mon, 27 Dec 2010 18:38:48 +0200 Subject: [PATCH] Added initial version of ntpd module --- ntpd/manifests/init.pp | 80 ++++++++++++++++++++++++++++++++ ntpd/templates/ntp.conf.erb | 20 ++++++++ ntpd/templates/openntpd.conf.erb | 18 +++++++ 3 files changed, 118 insertions(+) create mode 100644 ntpd/manifests/init.pp create mode 100644 ntpd/templates/ntp.conf.erb create mode 100644 ntpd/templates/openntpd.conf.erb diff --git a/ntpd/manifests/init.pp b/ntpd/manifests/init.pp new file mode 100644 index 0000000..0b67598 --- /dev/null +++ b/ntpd/manifests/init.pp @@ -0,0 +1,80 @@ +# Install and configure NTP daemon. +# +# === Global variables +# +# $ntp_server: +# Array of NTP servers. +# +class ntpd { + + if !$ntp_server { + $ntp_server = ["pool.ntp.org"] + } + + case $kernel { + linux: { + include ntpd::isc-ntpd + } + openbsd: { + include ntpd::openntpd + } + } + +} + + +# Install and configure ISC NTP. +# +class ntpd::isc-ntpd { + + package { "ntp": + ensure => installed, + } + + file { "/etc/ntp.conf": + ensure => present, + mode => 0644, + owner => root, + group => root, + content => template("ntpd/ntp.conf.erb"), + require => Package["ntp"], + notify => Service["ntpd"], + } + + service { "ntpd": + ensure => running, + enable => true, + name => $operatingsystem ? { + ubuntu => "ntp", + debian => "ntp", + default => "ntpd", + }, + } + +} + + +# Install and configure OpenNTPD. +# +class ntpd::openntpd { + + file { "/etc/ntpd.conf": + ensure => present, + mode => 0644, + owner => root, + group => wheel, + content => template("ntpd/openntpd.conf.erb"), + notify => Service["ntpd"], + } + + service { "ntpd": + ensure => running, + enable => true, + binary => "ntpd", + start => "ntpd -s", + stop => "pkill -u _ntp", + status => "pgrep -u _ntp", + require => File["/etc/ntpd.conf"], + } + +} diff --git a/ntpd/templates/ntp.conf.erb b/ntpd/templates/ntp.conf.erb new file mode 100644 index 0000000..1126a66 --- /dev/null +++ b/ntpd/templates/ntp.conf.erb @@ -0,0 +1,20 @@ +# By default, exchange time with everybody, but don't allow configuration. +restrict -4 default kod notrap nomodify nopeer noquery +restrict -6 default kod notrap nomodify nopeer noquery + +# Local users may interrogate the ntp server more closely. +restrict 127.0.0.1 +restrict ::1 + +# Drift file. +driftfile /var/lib/ntp/ntp.drift + +# Remote servers. +<% ntp_server.each do |server| -%> +server <%= server %> +<% end -%> + +# Undisciplined Local Clock. This is a fake driver intended for backup +# and when no outside source of synchronized time is available. +server 127.127.1.0 +fudge 127.127.1.0 stratum 10 diff --git a/ntpd/templates/openntpd.conf.erb b/ntpd/templates/openntpd.conf.erb new file mode 100644 index 0000000..7d22739 --- /dev/null +++ b/ntpd/templates/openntpd.conf.erb @@ -0,0 +1,18 @@ +# sample ntpd configuration file, see ntpd.conf(5) + +# Addresses to listen on (ntpd does not listen by default) +listen on * + +# sync to a single server +#server ntp.example.org + +# use a random selection of NTP Pool Time Servers +<% ntp_server.each do |server| -%> +servers <%= server %> +<% end -%> + +# use a specific local timedelta sensor (radio clock, etc) +#sensor nmea0 + +# use all detected timedelta sensors +#sensor *