From 46b2d2c9f77fbe6ef85881b6111c36f77f79ee0e Mon Sep 17 00:00:00 2001 From: Patrick Schoenfeld Date: Thu, 14 Jan 2016 15:25:37 +0100 Subject: [PATCH] Add parameter for interfaces to ignore The ntp configuration supports some tokens for interfaces that shall be ignored. Previously the module used the pattern 'wildcard' to indicate that ntp shouldn't listen to any interface but those specified as listen interfaces. In some circumstances this is not enough. This commit adds a new parameter interfaces_ignore that allows to list all interfaces (or interface tokens like all, ipv6, ipv6 etc.) that should be ignored. --- README.markdown | 4 ++++ manifests/init.pp | 1 + manifests/params.pp | 1 + spec/classes/ntp_spec.rb | 23 +++++++++++++++++++++++ templates/ntp.conf.erb | 6 ++++++ 5 files changed, 35 insertions(+) diff --git a/README.markdown b/README.markdown index b620621a..b975c837 100644 --- a/README.markdown +++ b/README.markdown @@ -190,6 +190,10 @@ Specifies whether to enable the iburst option for every NTP peer. Valid options: Specifies one or more network interfaces for NTP to listen on. Valid options: array. Default value: [ ] +####`interfaces_ignore` + +Specifies one or more ignore pattern for the NTP listener configuration (e.g. all, wildcard, ipv6, ...). Valid options: array. Default value: [ ] + ####`keys_controlkey` Provides a control key to be used by NTP. Valid options: string. Default value: ' ' diff --git a/manifests/init.pp b/manifests/init.pp index 774d88f4..064ec7da 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -29,6 +29,7 @@ $preferred_servers = $ntp::params::preferred_servers, $restrict = $ntp::params::restrict, $interfaces = $ntp::params::interfaces, + $interfaces_ignore = $ntp::params::interfaces_ignore, $servers = $ntp::params::servers, $service_enable = $ntp::params::service_enable, $service_ensure = $ntp::params::service_ensure, diff --git a/manifests/params.pp b/manifests/params.pp index ec538953..c3e549fe 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -21,6 +21,7 @@ $udlc = false $udlc_stratum = '10' $interfaces = [] + $interfaces_ignore = [] $disable_auth = false $disable_kernel = false $disable_monitor = true diff --git a/spec/classes/ntp_spec.rb b/spec/classes/ntp_spec.rb index b01717b6..1fd8c80a 100644 --- a/spec/classes/ntp_spec.rb +++ b/spec/classes/ntp_spec.rb @@ -126,6 +126,29 @@ end end + describe 'specified ignore interfaces' do + context "when set" do + let(:params) {{ + :interfaces => ['a.b.c.d'], + :interfaces_ignore => ['wildcard', 'ipv6'] + }} + + it { should contain_file('/etc/ntp.conf').with({ + 'content' => /interface ignore wildcard\ninterface ignore ipv6\ninterface listen a.b.c.d/}) + } + end + context "when not set" do + let(:params) {{ + :interfaces => ['127.0.0.1'], + :servers => ['a', 'b', 'c', 'd'], + }} + + it { should contain_file('/etc/ntp.conf').with({ + 'content' => /interface ignore wildcard\ninterface listen 127.0.0.1/}) + } + end + end + describe 'with parameter disable_auth' do context 'when set to true' do let(:params) {{ diff --git a/templates/ntp.conf.erb b/templates/ntp.conf.erb index c8c17677..8bc3a01a 100644 --- a/templates/ntp.conf.erb +++ b/templates/ntp.conf.erb @@ -27,9 +27,15 @@ restrict <%= restrict %> <% end -%> <% if @interfaces != [] -%> +<% if @interfaces_ignore != [] -%> +<% @interfaces_ignore.flatten.each do |interface| -%> +interface ignore <%= interface %> +<% end -%> +<% else -%> # Ignore wildcard interface and only listen on the following specified # interfaces interface ignore wildcard +<% end -%> <% @interfaces.flatten.each do |interface| -%> interface listen <%= interface %> <% end -%>