diff options
-rw-r--r-- | manifests/init.pp | 30 | ||||
-rw-r--r-- | spec/classes/ntp_spec.rb | 115 | ||||
-rw-r--r-- | templates/ntp.conf.suse.erb | 85 |
3 files changed, 170 insertions, 60 deletions
diff --git a/manifests/init.pp b/manifests/init.pp index 29358bd..9cf2f6e 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -60,8 +60,9 @@ class ntp($servers='UNSET', fail('autoupdate parameter must be true or false') } - case $::operatingsystem { - debian, ubuntu: { + case $::osfamily { + Debian: { + $supported = true $pkg_name = [ 'ntp' ] $svc_name = 'ntp' $config = '/etc/ntp.conf' @@ -75,7 +76,8 @@ class ntp($servers='UNSET', $servers_real = $servers } } - centos, redhat, oel, linux, fedora, Amazon: { + RedHat: { + $supported = true $pkg_name = [ 'ntp' ] $svc_name = 'ntpd' $config = '/etc/ntp.conf' @@ -88,7 +90,23 @@ class ntp($servers='UNSET', $servers_real = $servers } } - freebsd: { + SuSE: { + $supported = true + $pkg_name = [ 'ntp' ] + $svc_name = 'ntp' + $config = '/etc/ntp.conf' + $config_tpl = 'ntp.conf.suse.erb' + if ($servers == 'UNSET') { + $servers_real = [ '0.opensuse.pool.ntp.org', + '1.opensuse.pool.ntp.org', + '2.opensuse.pool.ntp.org', + '3.opensuse.pool.ntp.org', ] + } else { + $servers_real = $servers + } + } + FreeBSD: { + $supported = true $pkg_name = ['.*/net/ntp'] $svc_name = 'ntpd' $config = '/etc/ntp.conf' @@ -103,13 +121,13 @@ class ntp($servers='UNSET', } } default: { - fail("The ${module_name} module is not supported on ${::operatingsystem}") + fail("The ${module_name} module is not supported on ${::osfamily} based systems") } } package { 'ntp': - name => $pkg_name, ensure => $package_ensure, + name => $pkg_name, } file { $config: diff --git a/spec/classes/ntp_spec.rb b/spec/classes/ntp_spec.rb index 389f085..6ff453f 100644 --- a/spec/classes/ntp_spec.rb +++ b/spec/classes/ntp_spec.rb @@ -11,80 +11,87 @@ describe 'ntp' do describe 'test platform specific resources' do - debianish = ['debian', 'ubuntu'] - redhatish = ['centos', 'redhat', 'oel', 'linux'] - bsdish = ['freebsd'] - - debianish.each do |os| - describe "for operating system #{os}" do - - let(:params) {{}} - let(:facts) { { :operatingsystem => os } } - - it { should contain_service('ntp').with_name('ntp') } - it 'should use the debian ntp servers by default' do - content = param_value(subject, 'file', '/etc/ntp.conf', 'content') - expected_lines = ['server 0.debian.pool.ntp.org iburst', - 'server 1.debian.pool.ntp.org iburst', - 'server 2.debian.pool.ntp.org iburst', - 'server 3.debian.pool.ntp.org iburst'] - (content.split("\n") & expected_lines).should == expected_lines - end + describe "for operating system family Debian" do + + let(:params) {{}} + let(:facts) { { :osfamily => 'debian' } } + + it { should contain_service('ntp').with_name('ntp') } + it 'should use the debian ntp servers by default' do + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') + expected_lines = ['server 0.debian.pool.ntp.org iburst', + 'server 1.debian.pool.ntp.org iburst', + 'server 2.debian.pool.ntp.org iburst', + 'server 3.debian.pool.ntp.org iburst'] + (content.split("\n") & expected_lines).should == expected_lines end end - redhatish.each do |os| - describe "for operating system #{os}" do + describe "for operating system family RedHat" do - let(:params) {{}} - let(:facts) { { :operatingsystem => os } } + let(:params) {{}} + let(:facts) { { :osfamily => 'redhat' } } - it { should contain_service('ntp').with_name('ntpd') } - it 'should use the redhat ntp servers by default' do - content = param_value(subject, 'file', '/etc/ntp.conf', 'content') - expected_lines = [ - 'server 0.centos.pool.ntp.org', - 'server 1.centos.pool.ntp.org', - 'server 2.centos.pool.ntp.org'] - (content.split("\n") & expected_lines).should == expected_lines - end + it { should contain_service('ntp').with_name('ntpd') } + it 'should use the redhat ntp servers by default' do + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') + expected_lines = [ + 'server 0.centos.pool.ntp.org', + 'server 1.centos.pool.ntp.org', + 'server 2.centos.pool.ntp.org'] + (content.split("\n") & expected_lines).should == expected_lines end end - bsdish.each do |os| - describe "for operating system #{os}" do - - let(:params) {{}} - let(:facts) { { :operatingsystem => os } } - - it { should contain_service('ntp').with_name('ntpd') } - it 'should use the freebsd ntp servers by default' do - content = param_value(subject, 'file', '/etc/ntp.conf', 'content') - expected_lines = [ - "server 0.freebsd.pool.ntp.org iburst maxpoll 9", - "server 1.freebsd.pool.ntp.org iburst maxpoll 9", - "server 2.freebsd.pool.ntp.org iburst maxpoll 9", - "server 3.freebsd.pool.ntp.org iburst maxpoll 9"] - (content.split("\n") & expected_lines).should == expected_lines - end + describe "for operating system family SuSE" do + + let(:params) {{}} + let(:facts) { { :osfamily => 'suse' } } + + it { should contain_service('ntp').with_name('ntp') } + it 'should use the redhat ntp servers by default' do + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') + expected_lines = [ + 'server 0.opensuse.pool.ntp.org', + 'server 1.opensuse.pool.ntp.org', + 'server 2.opensuse.pool.ntp.org', + 'server 3.opensuse.pool.ntp.org'] + (content.split("\n") & expected_lines).should == expected_lines + end + end + + describe "for operating system family FreeBSD" do + + let(:params) {{}} + let(:facts) { { :osfamily => 'freebsd' } } + + it { should contain_service('ntp').with_name('ntpd') } + it 'should use the freebsd ntp servers by default' do + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') + expected_lines = [ + "server 0.freebsd.pool.ntp.org iburst maxpoll 9", + "server 1.freebsd.pool.ntp.org iburst maxpoll 9", + "server 2.freebsd.pool.ntp.org iburst maxpoll 9", + "server 3.freebsd.pool.ntp.org iburst maxpoll 9"] + (content.split("\n") & expected_lines).should == expected_lines end - describe "for operating system unsupported" do + describe "for operating system family unsupported" do let(:facts) {{ - :operatingsystem => 'unsupported', + :osfamily => 'unsupported', }} it { expect{ subject }.to raise_error( - /^The ntp module is not supported on unsupported/ + /^The ntp module is not supported on unsupported based systems/ )} end end - (redhatish + debianish + bsdish).each do |os| - describe "for operating system #{os}" do + ['Debian', 'RedHat','SuSE', 'FreeBSD'].each do |osfamily| + describe "for operating system family #{osfamily}" do - let(:facts) { { :operatingsystem => os } } + let(:facts) { { :osfamily => osfamily } } it { should contain_file('/etc/ntp.conf').with_owner('0') } it { should contain_file('/etc/ntp.conf').with_group('0') } diff --git a/templates/ntp.conf.suse.erb b/templates/ntp.conf.suse.erb new file mode 100644 index 0000000..b25aac2 --- /dev/null +++ b/templates/ntp.conf.suse.erb @@ -0,0 +1,85 @@ +################################################################################ +## /etc/ntp.conf +## +## Sample NTP configuration file. +## See package 'ntp-doc' for documentation, Mini-HOWTO and FAQ. +## Copyright (c) 1998 S.u.S.E. GmbH Fuerth, Germany. +## +## Author: Michael Andres, <ma@suse.de> +## Michael Skibbe, <mskibbe@suse.de> +## +################################################################################ + +## +## Radio and modem clocks by convention have addresses in the +## form 127.127.t.u, where t is the clock type and u is a unit +## number in the range 0-3. +## +## Most of these clocks require support in the form of a +## serial port or special bus peripheral. The particular +## device is normally specified by adding a soft link +## /dev/device-u to the particular hardware device involved, +## where u correspond to the unit number above. +## +## Generic DCF77 clock on serial port (Conrad DCF77) +## Address: 127.127.8.u +## Serial Port: /dev/refclock-u +## +## (create soft link /dev/refclock-0 to the particular ttyS?) +## +# server 127.127.8.0 mode 5 prefer + +## +## 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 # local clock (LCL) +fudge 127.127.1.0 stratum 10 # LCL is unsynchronized + +# Managed by puppet class { "ntp": servers => [ ... ] } +<% [servers_real].flatten.each do |server| -%> +server <%= server %> +<% end -%> + +<% if @is_virtual == "true" -%> +# Keep ntpd from panicking in the event of a large clock skew +# when a VM guest is suspended and resumed. +tinker panic 0 + +<% end -%> +## +## Miscellaneous stuff +## + +driftfile /var/lib/ntp/drift/ntp.drift # path for drift file + +logfile /var/log/ntp # alternate log file +# logconfig =syncstatus + sysevents +# logconfig =all + +# statsdir /tmp/ # directory for statistics files +# filegen peerstats file peerstats type day enable +# filegen loopstats file loopstats type day enable +# filegen clockstats file clockstats type day enable + +<% if @restrict -%> +# Permit time synchronization with our time source, but do not +# permit the source to query or modify the service on this system. +restrict -4 default kod nomodify notrap nopeer noquery +restrict -6 default kod nomodify notrap nopeer noquery + +# Permit all access over the loopback interface. This could +# be tightened as well, but to do so would effect some of +# the administrative functions. +restrict 127.0.0.1 +restrict -6 ::1 + +<% end -%> + +# +# Authentication stuff +# +keys /etc/ntp.keys # path for keys file +trustedkey 1 # define trusted keys +requestkey 1 # key (7) for accessing server variables +# controlkey 15 # key (6) for accessing server variables |