diff --git a/manifests/ini_file.pp b/manifests/ini_file.pp index c2cdb3d467ede8e0c7119855dc1938ccca618530..0b0415afb82fe7337b918276474c060adb0c6f12 100644 --- a/manifests/ini_file.pp +++ b/manifests/ini_file.pp @@ -1,4 +1,4 @@ -# Copyright (C) 2014-2020 Thomas Bellman. +# Copyright (C) 2014-2024 Thomas Bellman. # Licensed under the GNU LGPL v3+; see the README file for more information. @@ -37,17 +37,10 @@ define cfgfile::ini_file($settings, $ensure='present', { if ($ensure == 'present') { - $content = inline_template( - '<%= @settings.sort.collect { |section_name,section_vars| - "[" + section_name + "]\n" + - section_vars.sort.collect { |k,v| - k + " = " + v.to_s - }.join("\n") - }.join("\n\n") + "\n" - %>') file { $name: - ensure => file, content => $content, + ensure => file, + content => template('cfgfile/ini_file.erb'), owner => $owner, group => $group, mode => $mode; } } diff --git a/templates/ini_file.erb b/templates/ini_file.erb new file mode 100644 index 0000000000000000000000000000000000000000..59b9019cef6f13b4dfa0105bd5e28c2a8f5d5da0 --- /dev/null +++ b/templates/ini_file.erb @@ -0,0 +1,19 @@ +<% + # Copyright (C) 2024 Thomas Bellman. + # Licensed under the GNU LGPL v3+; see the README file for more information. + # +-%> +<% @settings.sort().each do |section_name, section_vars| -%> +[<%= section_name %>] +<% # Want to align = signs, but only for "short" names + max_align_pos = 24 + shortnames = section_vars.keys().select { |name| + name.length() < max_align_pos - 1 + } + namewidth = ( shortnames.max_by { |name| name.length() } or "" ).length() + section_vars.sort.each do |key,value| +-%> +<%= sprintf('%-*s = %s', namewidth, key, value.to_s).rstrip() %> +<% end -%> + +<% end -%>