diff --git a/manifests/config.pp b/manifests/config.pp index e55c2e93f..d4077641d 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -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', + order => '0_comment', + } + file { $puppet_dir: ensure => directory, owner => $puppet::dir_owner, @@ -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', } } } diff --git a/manifests/config/entry.pp b/manifests/config/entry.pp index a9a1844d0..cf30f4719 100644 --- a/manifests/config/entry.pp +++ b/manifests/config/entry.pp @@ -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 { diff --git a/spec/defines/puppet_config_entry_spec.rb b/spec/defines/puppet_config_entry_spec.rb index f71c1e454..43886aa50 100644 --- a/spec/defines/puppet_config_entry_spec.rb +++ b/spec/defines/puppet_config_entry_spec.rb @@ -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 ") @@ -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 ") @@ -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 ")