Skip to content

Commit

Permalink
Merge pull request #164 from directionless/master
Browse files Browse the repository at this point in the history
Add support for ntp `pool` configuration option
  • Loading branch information
tas50 committed Jun 27, 2017
2 parents c49f273 + 1cb6b00 commit 47c63ed
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -35,6 +35,12 @@ Installs and configures ntp. On Windows systems it uses the Meinberg port of the

The NTP protocol works best with at least 4 servers. The ntp daemon will disregard any server after the 10th listed, but will continue monitoring all listed servers. For more information, see [Upstream Server Time Quantity](http://support.ntp.org/bin/view/Support/SelectingOffsiteNTPServers#Section_5.3.3.) at [support.ntp.org](http://support.ntp.org).

- `ntp['pools']` - (applies to NTP Servers and Clients)

- Array, should be a list of upstream NTP pools that will be considered authoritative by the local NTP daemon. The local NTP daemon will act as a client, adjusting local time to match time data retrieved from each of the servers in the upstream pool.

See this [Release Announcement](http://lists.ntp.org/pipermail/questions/2010-April/026304.html) for discussion about tuning this option.

- `ntp['peers']` - (applies to NTP Servers ONLY)

- Array, should be a list of local NTP peers. For more information, see [Designing Your NTP Network](http://support.ntp.org/bin/view/Support/DesigningYourNTPNetwork) at [support.ntp.org](http://support.ntp.org).
Expand Down
1 change: 1 addition & 0 deletions attributes/default.rb
Expand Up @@ -24,6 +24,7 @@
# default attributes for all platforms
default['ntp']['servers'] = [] # The default recipe sets a list of common NTP servers (COOK-1170)
default['ntp']['peers'] = []
default['ntp']['pools'] = []
default['ntp']['restrictions'] = []
default['ntp']['tinker'] = { 'panic' => 0 }

Expand Down
18 changes: 18 additions & 0 deletions spec/unit/recipes/default_spec.rb
Expand Up @@ -76,6 +76,24 @@
end
end

context 'ntp["pools"] is used' do
let(:chef_run) do
runner = ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04')
runner.node.normal['ntp']['pools'] = %w(0.pool.ntp.org 1.pool.ntp.org)
runner.node.normal['ntp']['servers'] = %w()
runner.converge('ntp::default')
end

it 'creates ntp.conf appropriately' do
expect(chef_run).to render_file('/etc/ntp.conf')
.with_content('Auto-generated by Chef.')
expect(chef_run).to render_file('/etc/ntp.conf')
.with_content('pool 0.pool.ntp.org')
expect(chef_run).to render_file('/etc/ntp.conf')
.with_content('pool 1.pool.ntp.org')
end
end

context 'the ntp.conf' do
let(:template) { chef_run.template('/etc/ntp.conf') }

Expand Down
7 changes: 7 additions & 0 deletions templates/default/ntp.conf.erb
Expand Up @@ -68,6 +68,13 @@ disable monitor
<% end -%>
<% end -%>
<%# Configure upstream pools, if any. %>
<%# These are akin to servers, but support multiple dns records %>
<% ( node['ntp']['pools'] ).sort.each do |ntppool| -%>
<% -%>pool <%= ntppool %><% if node['ntp']['server']['use_iburst'] -%> iburst<% end -%><% if node['ntp']['server']['use_burst'] -%> burst<% end -%> minpoll <%= node['ntp']['server']['minpoll'] %> maxpoll <%= node['ntp']['server']['maxpoll'] %><% if node['ntp']['server']['prefer'] == ntppool -%> prefer<% end -%>
<% -%>restrict <%= ntppool %> nomodify notrap noquery
<% end -%>

restrict default <%= node['ntp']['restrict_default'] %>
restrict 127.0.0.1<%if node['ntp']['localhost']['noquery'] -%> noquery<% end -%>
restrict -6 default <%= node['ntp']['restrict_default'] %>
Expand Down

0 comments on commit 47c63ed

Please sign in to comment.