diff --git a/README.md b/README.md index ee89ed7..9c4060e 100644 --- a/README.md +++ b/README.md @@ -147,3 +147,9 @@ logfile Log file name - *Default*: none + +ignore_local_clock +------------------ +Boolean to ignore the local clock. By setting this to true it ensures local clock is not referenced, useful if local clock drifts. + +- *Default*: false diff --git a/manifests/init.pp b/manifests/init.pp index 9040a41..c31fe22 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -33,6 +33,7 @@ $enable_stats = false, $statsdir = '/var/log/ntpstats/', $logfile = 'UNSET', + $ignore_local_clock = false, ) { # validate type and convert string to boolean if necessary @@ -89,6 +90,13 @@ $service_enable = false } + if type($ignore_local_clock) == 'string' { + $my_ignore_local_clock = str2bool($ignore_local_clock) + } else { + $my_ignore_local_clock = $ignore_local_clock + } + validate_bool($my_ignore_local_clock) + case $::osfamily { 'Debian': { $default_package_name = [ 'ntp' ] diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 86723b3..391a6a8 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -29,7 +29,7 @@ it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged/) } it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } it { should contain_file('ntp_conf').with_content(/^keys \/etc\/ntp\/keys$/) } - it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) } + it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) } it { should contain_file('ntp_conf').with_content(/^restrict -4 default kod notrap nomodify nopeer noquery$/) } it { should contain_file('ntp_conf').with_content(/^restrict -6 default kod notrap nomodify nopeer noquery$/) } @@ -81,7 +81,7 @@ it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged/) } it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } it { should contain_file('ntp_conf').with_content(/^keys \/etc\/ntp\/keys$/) } - it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) } + it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) } it { should contain_file('ntp_conf').with_content(/^restrict -4 default kod notrap nomodify nopeer noquery$/) } it { should contain_file('ntp_conf').with_content(/^restrict -6 default kod notrap nomodify nopeer noquery$/) } @@ -126,7 +126,7 @@ it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged/) } it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } it { should contain_file('ntp_conf').with_content(/^keys \/etc\/ntp\/keys$/) } - it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) } + it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) } it { should contain_file('ntp_conf').with_content(/^restrict -4 default kod notrap nomodify nopeer noquery$/) } it { should contain_file('ntp_conf').with_content(/^restrict -6 default kod notrap nomodify nopeer noquery$/) } @@ -213,7 +213,7 @@ it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged/) } it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } it { should contain_file('ntp_conf').with_content(/^keys \/etc\/inet\/ntp.keys$/) } - it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) } + it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) } it { should contain_file('ntp_conf').with_content(/^restrict -4 default kod notrap nomodify nopeer noquery$/) } it { should contain_file('ntp_conf').with_content(/^restrict -6 default kod notrap nomodify nopeer noquery$/) } @@ -277,7 +277,7 @@ it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged/) } it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } it { should contain_file('ntp_conf').with_content(/^keys \/etc\/inet\/ntp.keys$/) } - it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) } + it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) } it { should contain_file('ntp_conf').with_content(/^restrict -4 default kod notrap nomodify nopeer noquery$/) } it { should contain_file('ntp_conf').with_content(/^restrict -6 default kod notrap nomodify nopeer noquery$/) } @@ -335,7 +335,7 @@ it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged/) } it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } it { should contain_file('ntp_conf').with_content(/^keys \/etc\/inet\/ntp.keys$/) } - it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) } + it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) } it { should contain_file('ntp_conf').with_content(/^restrict -4 default kod notrap nomodify nopeer noquery$/) } it { should contain_file('ntp_conf').with_content(/^restrict -6 default kod notrap nomodify nopeer noquery$/) } @@ -395,7 +395,7 @@ it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged/) } it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } it { should contain_file('ntp_conf').with_content(/^keys \/etc\/inet\/ntp.keys$/) } - it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) } + it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) } it { should_not contain_file('admin_file') } @@ -445,7 +445,7 @@ it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged/) } it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } it { should contain_file('ntp_conf').with_content(/^keys \/etc\/inet\/ntp.keys$/) } - it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) } + it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) } it { should contain_file('admin_file').with({ @@ -501,7 +501,7 @@ it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged/) } it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } it { should_not contain_file('ntp_conf').with_content(/^keys \/etc\/ntp\/keys$/) } - it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) } + it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) } it { should contain_file('ntp_conf').with_content(/^restrict -4 default kod notrap nomodify nopeer noquery$/) } it { should contain_file('ntp_conf').with_content(/^restrict -6 default kod notrap nomodify nopeer noquery$/) } @@ -555,7 +555,7 @@ it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged/) } it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } it { should_not contain_file('ntp_conf').with_content(/^keys \/etc\/ntp\/keys$/) } - it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) } + it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) } it { should contain_file('ntp_conf').with_content(/^restrict -4 default kod notrap nomodify nopeer noquery$/) } it { should contain_file('ntp_conf').with_content(/^restrict -6 default kod notrap nomodify nopeer noquery$/) } @@ -747,5 +747,20 @@ end end + describe 'with ignore_local_clock set' do + let(:facts) { { :osfamily => 'RedHat' } } + + context 'to true' do + let(:params) { { :ignore_local_clock => true } } + + it { should contain_file('ntp_conf').with_content(/^#fudge 127.127.1.0 stratum 10/) } + end + + context 'to false' do + let(:params) { { :ignore_local_clock => false } } + + it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) } + end + end end diff --git a/templates/ntp.conf.erb b/templates/ntp.conf.erb index 6f1e432..130b812 100644 --- a/templates/ntp.conf.erb +++ b/templates/ntp.conf.erb @@ -66,8 +66,13 @@ restrict ::1 # Undisciplined Local Clock. This is a fake driver intended for backup # and when no outside source of synchronized time is available. +<% if @my_ignore_local_clock == true -%> +#server 127.127.1.0 # local clock +#fudge 127.127.1.0 stratum <%= @fudge_stratum %> +<% else %> server 127.127.1.0 # local clock fudge 127.127.1.0 stratum <%= @fudge_stratum %> +<% end -%> <% if @keys_real -%> # Key file containing the keys and key identifiers used when operating