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

Fix config append #782

Merged
merged 2 commits into from
Mar 29, 2021
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
16 changes: 10 additions & 6 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
puppet::config::main { $key: value => $value }
}

concat::fragment { 'puppet.conf_comment':
target => "${puppet_dir}/puppet.conf",
content => '# file managed by puppet',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice solution to the otherwise empty line.

order => '0_comment',
}

file { $puppet_dir:
ensure => directory,
owner => $puppet::dir_owner,
Expand All @@ -81,17 +87,15 @@
-> case $facts['os']['family'] {
'Windows': {
concat { "${puppet_dir}/puppet.conf":
mode => '0674',
ensure_newline => true,
mode => '0674',
}
}

default: {
concat { "${puppet_dir}/puppet.conf":
owner => 'root',
group => $puppet::params::root_group,
mode => '0644',
ensure_newline => true,
owner => 'root',
group => $puppet::params::root_group,
mode => '0644',
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion manifests/config/entry.pp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,18 @@
content => "\n[${section}]",
order => "${sectionorder}_${section} ",
})
ensure_resource('concat::fragment', "puppet.conf_${section}_end", {
target => "${puppet::dir}/puppet.conf",
content => "\n",
order => "${sectionorder}_${section}~end",
})

# this adds the '$key =' for the first value,
# otherwise it just appends it with the joiner to separate it from the previous value.
if (!defined(Concat::Fragment["puppet.conf_${section}_${key}"])){
concat::fragment{"puppet.conf_${section}_${key}":
target => "${puppet::dir}/puppet.conf",
content => " ${key} = ${_value}",
content => "\n ${key} = ${_value}",
order => "${sectionorder}_${section}_${key} ",
}
} else {
Expand Down
12 changes: 12 additions & 0 deletions spec/defines/puppet_config_entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
should contain_concat__fragment('puppet.conf_main').with_content("\n[main]")
should contain_concat__fragment('puppet.conf_main').with_order("1_main ")
end
it 'should contain the section end' do
should contain_concat__fragment('puppet.conf_main_end').with_content("\n")
should contain_concat__fragment('puppet.conf_main_end').with_order("1_main~end")
end
it 'should contain the keyvalue pair' do
should contain_concat__fragment('puppet.conf_main_foo').with_content(/^\s+foo = bar$/)
should contain_concat__fragment('puppet.conf_main_foo').with_order("1_main_foo ")
Expand All @@ -44,6 +48,10 @@
should contain_concat__fragment('puppet.conf_main').with_content("\n[main]")
should contain_concat__fragment('puppet.conf_main').with_order("1_main ")
end
it 'should contain the section end' do
should contain_concat__fragment('puppet.conf_main_end').with_content("\n")
should contain_concat__fragment('puppet.conf_main_end').with_order("1_main~end")
end
it 'should contain the keyvalue pair' do
should contain_concat__fragment('puppet.conf_main_foo').with_content(/^\s+foo = bar,baz$/)
should contain_concat__fragment('puppet.conf_main_foo').with_order("1_main_foo ")
Expand All @@ -66,6 +74,10 @@
should contain_concat__fragment('puppet.conf_main').with_content("\n[main]")
should contain_concat__fragment('puppet.conf_main').with_order("1_main ")
end
it 'should contain the section end' do
should contain_concat__fragment('puppet.conf_main_end').with_content("\n")
should contain_concat__fragment('puppet.conf_main_end').with_order("1_main~end")
end
it 'should contain the keyvalue pair' do
should contain_concat__fragment('puppet.conf_main_foo').with_content(/^\s+foo = bar:baz$/)
should contain_concat__fragment('puppet.conf_main_foo').with_order("1_main_foo ")
Expand Down