From 04c9e5c4176fcdf3474ed35b880f92e2b1d133e3 Mon Sep 17 00:00:00 2001 From: Simon Peeters Date: Fri, 19 Mar 2021 14:05:11 +0100 Subject: [PATCH 1/2] Revert "Ensure config file ends with a new line" This reverts commit e87d8f2a7a008e2d92f5e41999fee83117edec25. --- manifests/config.pp | 10 ++++------ manifests/config/entry.pp | 4 ++-- spec/defines/puppet_config_entry_spec.rb | 6 +++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index e55c2e93f..1f4d7703c 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -81,17 +81,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..1ac7f75cf 100644 --- a/manifests/config/entry.pp +++ b/manifests/config/entry.pp @@ -30,7 +30,7 @@ # they make sure that '1_main ' is ordered before '1_main_*' ensure_resource('concat::fragment', "puppet.conf_${section}", { target => "${puppet::dir}/puppet.conf", - content => "\n[${section}]", + content => "\n\n[${section}]", order => "${sectionorder}_${section} ", }) @@ -39,7 +39,7 @@ 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..73f2157f9 100644 --- a/spec/defines/puppet_config_entry_spec.rb +++ b/spec/defines/puppet_config_entry_spec.rb @@ -20,7 +20,7 @@ } end it 'should contain the section header' do - should contain_concat__fragment('puppet.conf_main').with_content("\n[main]") + should contain_concat__fragment('puppet.conf_main').with_content("\n\n[main]") should contain_concat__fragment('puppet.conf_main').with_order("1_main ") end it 'should contain the keyvalue pair' do @@ -41,7 +41,7 @@ } end it 'should contain the section header' do - should contain_concat__fragment('puppet.conf_main').with_content("\n[main]") + should contain_concat__fragment('puppet.conf_main').with_content("\n\n[main]") should contain_concat__fragment('puppet.conf_main').with_order("1_main ") end it 'should contain the keyvalue pair' do @@ -63,7 +63,7 @@ } end it 'should contain the section header' do - should contain_concat__fragment('puppet.conf_main').with_content("\n[main]") + should contain_concat__fragment('puppet.conf_main').with_content("\n\n[main]") should contain_concat__fragment('puppet.conf_main').with_order("1_main ") end it 'should contain the keyvalue pair' do From ed7732757ba29c2bd18ce80a0595a163ca4b0193 Mon Sep 17 00:00:00 2001 From: Simon Peeters Date: Fri, 19 Mar 2021 15:54:19 +0100 Subject: [PATCH 2/2] Add newline at the end of each config block --- manifests/config.pp | 6 ++++++ manifests/config/entry.pp | 7 ++++++- spec/defines/puppet_config_entry_spec.rb | 18 +++++++++++++++--- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 1f4d7703c..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, diff --git a/manifests/config/entry.pp b/manifests/config/entry.pp index 1ac7f75cf..cf30f4719 100644 --- a/manifests/config/entry.pp +++ b/manifests/config/entry.pp @@ -30,9 +30,14 @@ # they make sure that '1_main ' is ordered before '1_main_*' ensure_resource('concat::fragment', "puppet.conf_${section}", { target => "${puppet::dir}/puppet.conf", - content => "\n\n[${section}]", + 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. diff --git a/spec/defines/puppet_config_entry_spec.rb b/spec/defines/puppet_config_entry_spec.rb index 73f2157f9..43886aa50 100644 --- a/spec/defines/puppet_config_entry_spec.rb +++ b/spec/defines/puppet_config_entry_spec.rb @@ -20,9 +20,13 @@ } end it 'should contain the section header' do - should contain_concat__fragment('puppet.conf_main').with_content("\n\n[main]") + 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 ") @@ -41,9 +45,13 @@ } end it 'should contain the section header' do - should contain_concat__fragment('puppet.conf_main').with_content("\n\n[main]") + 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 ") @@ -63,9 +71,13 @@ } end it 'should contain the section header' do - should contain_concat__fragment('puppet.conf_main').with_content("\n\n[main]") + 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 ")