Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhanced default configuration #297

Merged
merged 9 commits into from
Nov 19, 2015
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake
matrix:
fast_finish: true
include:
- rvm: 1.8.7
env: PUPPET_GEM_VERSION="~> 3.0"
- rvm: 1.9.3
env: PUPPET_GEM_VERSION="~> 3.0"
- rvm: 2.1.5
Expand All @@ -16,9 +14,5 @@ matrix:
env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes"
- rvm: 2.1.6
env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes"
- rvm: 1.8.7
env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0"
- rvm: 1.8.7
env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0"
notifications:
email: false
5 changes: 5 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ Enable reception of broadcast server messages to any local interface.

Specifies a file for ntp's configuration info. Valid options: string containing an absolute path. Default value: '/etc/ntp.conf' (or '/etc/inet/ntp.conf' on Solaris)


####`config_dir`

Specifies a directory for the ntp configuration files. Valid options: string containing an absolute path. Default value: undef

####`config_file_mode`

Specifies a file mode for the ntp configuration file. Valid options: string containing file mode. Default value: '0664'
Expand Down
23 changes: 15 additions & 8 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@
class ntp::config inherits ntp {

if $ntp::keys_enable {
$directory = dirname($ntp::keys_file)
case $directory {
'/', '/etc': {}
case $ntp::config_dir {
'/', '/etc', undef: {}
default: {
file { $directory:
ensure => directory,
owner => 0,
group => 0,
mode => '0755',
file { $ntp::config_dir:
ensure => directory,
owner => 0,
group => 0,
mode => '0664',
recurse => false,
}
}
}

file { $ntp::keys_file:
ensure => file,
owner => 0,
group => 0,
mode => '0664',
}
}

file { $ntp::config:
Expand Down
5 changes: 5 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
$autoupdate = $ntp::params::autoupdate,
$broadcastclient = $ntp::params::broadcastclient,
$config = $ntp::params::config,
$config_dir = $ntp::params::config_dir,
$config_file_mode = $ntp::params::config_file_mode,
$config_template = $ntp::params::config_template,
$disable_auth = $ntp::params::disable_auth,
Expand Down Expand Up @@ -86,6 +87,10 @@
validate_bool($udlc)
validate_array($peers)

if $config_dir {
validate_absolute_path($config_dir)
}

if $autoupdate {
notice('autoupdate parameter has been deprecated and replaced with package_ensure. Set this to latest for the same behavior as autoupdate => true.')
}
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class ntp::params {

$autoupdate = false
$config_dir = undef
$config_file_mode = '0644'
$config_template = 'ntp/ntp.conf.erb'
$keys_enable = false
Expand Down
23 changes: 17 additions & 6 deletions spec/classes/ntp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@
:keys_requestkey => '3',
}}

it { should contain_file('/etc/ntp').with({
'ensure' => 'directory'})
}
it { should contain_file('/etc/ntp.conf').with({
'content' => /trustedkey 1 2 3/})
}
Expand All @@ -73,9 +70,6 @@
:keys_requestkey => '3',
}}

it { should_not contain_file('/etc/ntp').with({
'ensure' => 'directory'})
}
it { should_not contain_file('/etc/ntp.conf').with({
'content' => /trustedkey 1 2 3/})
}
Expand Down Expand Up @@ -228,6 +222,23 @@
})
end
end
context 'when setting custom config_dir' do
let(:params) {{
:keys_enable => true,
:config_dir => '/tmp/foo',
:keys_file => '/tmp/foo/ntp.keys',
}}

it 'should contain custom config directory' do
should contain_file('/tmp/foo').with(
'ensure' => 'directory',
'owner' => '0',
'group' => '0',
'mode' => '0664',
'recurse' => 'false'
)
end
end
context 'when manually setting conf file mode to 0777' do
let(:params) {{
:config_file_mode => '0777',
Expand Down