Skip to content

Commit

Permalink
Merge pull request #50 from hfm/space-separated
Browse files Browse the repository at this point in the history
Use a space-separated in timesyncd.conf
  • Loading branch information
bastelfreak committed Nov 23, 2017
2 parents 823f0b6 + 2c38f1a commit 246992e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ It is possible to configure the default ntp servers in /etc/systemd/timesyncd.co
```puppet
class{'::systemd':
$manage_timesyncd => true,
$ntp_server => '0.pool.ntp.org,1.pool.ntp.org',
$fallback_ntp_server => '2.pool.ntp.org,3.pool.ntp.org',
$ntp_server => ['0.pool.ntp.org', '1.pool.ntp.org'],
$fallback_ntp_server => ['2.pool.ntp.org', '3.pool.ntp.org'],
}
```

Expand Down
4 changes: 2 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
Enum['stopped','running'] $networkd_ensure = 'running',
Boolean $manage_timesyncd = false,
Enum['stopped','running'] $timesyncd_ensure = 'running',
Optional[String] $ntp_server = undef,
Optional[String] $fallback_ntp_server = undef,
Optional[Variant[Array,String]] $ntp_server = undef,
Optional[Variant[Array,String]] $fallback_ntp_server = undef,
){

contain ::systemd::systemctl::daemon_reload
Expand Down
6 changes: 3 additions & 3 deletions manifests/timesyncd.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# The state that the ``networkd`` service should be in
#
# @param $ntp_server
# comma separated list of ntp servers, will be combined with interface specific
# A space-separated list of NTP servers, will be combined with interface specific
# addresses from systemd-networkd. requires puppetlabs-inifile
#
# @param fallback_ntp_server
Expand Down Expand Up @@ -36,7 +36,7 @@
if $ntp_server =~ String {
$_ntp_server = $ntp_server
} else {
$_ntp_server = join($ntp_server, ',')
$_ntp_server = join($ntp_server, ' ')
}
ini_setting{'ntp_server':
ensure => 'present',
Expand All @@ -52,7 +52,7 @@
if $fallback_ntp_server =~ String {
$_fallback_ntp_server = $fallback_ntp_server
} else {
$_fallback_ntp_server = join($fallback_ntp_server, ',')
$_fallback_ntp_server = join($fallback_ntp_server, ' ')
}
ini_setting{'fallback_ntp_server':
ensure => 'present',
Expand Down
17 changes: 14 additions & 3 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,22 @@
it { is_expected.not_to create_service('systemd-networkd').with_enable(true) }
end

context 'when enabling timesyncd with NTP values' do
context 'when enabling timesyncd with NTP values (string)' do
let(:params) {{
:manage_timesyncd => true,
:ntp_server => '0.pool.ntp.org,1.pool.ntp.org',
:fallback_ntp_server => '2.pool.ntp.org,3.pool.ntp.org'
:ntp_server => '0.pool.ntp.org 1.pool.ntp.org',
:fallback_ntp_server => '2.pool.ntp.org 3.pool.ntp.org'
}}
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_ini_setting('ntp_server')}
it { is_expected.to contain_ini_setting('fallback_ntp_server')}
end

context 'when enabling timesyncd with NTP values (array)' do
let(:params) {{
:manage_timesyncd => true,
:ntp_server => %w(0.pool.ntp.org 1.pool.ntp.org),
:fallback_ntp_server => %w(2.pool.ntp.org 3.pool.ntp.org)
}}
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_ini_setting('ntp_server')}
Expand Down

0 comments on commit 246992e

Please sign in to comment.