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

make config_keys option optional #156

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ Default value: `'chrony/chrony.conf.epp'`

##### <a name="config_keys"></a>`config_keys`

Data type: `Stdlib::Unixpath`
Data type: `Variant[Stdlib::Unixpath,String[0,0]]`

This sets the file to write chrony keys into.
This sets the file to write chrony keys into. Set to '' to remove `keyfile` attribute from the config.

Default value: `'/etc/chrony/chrony.keys'`

Expand Down
16 changes: 9 additions & 7 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
'keys' => $chrony::keys,
}

file { $chrony::config_keys:
ensure => file,
replace => $chrony::config_keys_manage,
owner => $chrony::config_keys_owner,
group => $chrony::config_keys_group,
mode => $chrony::config_keys_mode,
content => Sensitive(epp($chrony::config_keys_template, $keys_params)),
unless empty($chrony::config_keys) {
file { $chrony::config_keys:
ensure => file,
replace => $chrony::config_keys_manage,
owner => $chrony::config_keys_owner,
group => $chrony::config_keys_group,
mode => $chrony::config_keys_mode,
content => Sensitive(epp($chrony::config_keys_template, $keys_params)),
}
}
}
4 changes: 2 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
# @param config_template
# This determines which template puppet should use for the chrony configuration.
# @param config_keys
# This sets the file to write chrony keys into.
# This sets the file to write chrony keys into. Set to '' to remove `keyfile` attribute from the config.
# @param config_keys_manage
# Determines whether puppet will manage the content of the keys file after it has been created for the first time.
# @param config_keys_template
Expand Down Expand Up @@ -258,7 +258,7 @@
Optional[Stdlib::Absolutepath] $confdir = undef,
Optional[Stdlib::Absolutepath] $sourcedir = undef,
String[1] $config_template = 'chrony/chrony.conf.epp',
Stdlib::Unixpath $config_keys = '/etc/chrony/chrony.keys',
Variant[Stdlib::Unixpath,String[0,0]] $config_keys = '/etc/chrony/chrony.keys',
String[1] $config_keys_template = 'chrony/chrony.keys.epp',
Variant[Sensitive[String[1]], String[1]] $chrony_password = 'xyzzy',
Variant[Integer[0],String[1]] $config_keys_owner = 0,
Expand Down
13 changes: 13 additions & 0 deletions spec/classes/chrony_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@
it { is_expected.to contain_file('/etc/chrony/chrony.keys').with_content(sensitive("0 xyzzy\n")) }
end
end
it { is_expected.to contain_file(config_file).with_content(%r{keyfile .*chrony.keys}) }
end

context 'with empty config_keys' do
let :params do
{
config_keys: ''
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_file(config_file).without_content(%r{keyfile .*chrony.keys}) }
it { is_expected.not_to contain_file(keys_file) }
end

context 'with some params passed in' do
Expand Down
2 changes: 1 addition & 1 deletion templates/chrony.conf.epp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ minsamples <%= $chrony::minsamples %>
# https://chrony.tuxfamily.org/doc/3.4/chrony.conf.html#minsources
minsources <%= $chrony::minsources %>
<% } -%>
<% if $chrony::config_keys { -%>
<% unless empty($chrony::config_keys) { -%>

keyfile <%= $chrony::config_keys %>
<% } -%>
Expand Down