diff --git a/manifests/ini_file.pp b/manifests/ini_file.pp index 5eaa5a34c79663367c8e71cc64433aec87fc44ab..d0d93ba4060c17235faa7ebd0faa444b297c2c3e 100644 --- a/manifests/ini_file.pp +++ b/manifests/ini_file.pp @@ -12,6 +12,9 @@ * - settings Hash of hashes for the settings in the INI file. The outer * hash names the sections, and the inner hashes contain the * settings within each section. + * A section with the empty string ("") as name creates a + * "global" section placed first in the file with no section + * header. * * - kvsep Separator between the name and value for settings, normally * an equal sign (=), but some INI-style files use colon (:), @@ -40,17 +43,23 @@ * * { * 'smurfs' => { 'colour' => 'blue', 'population' => 99, }, - * 'gargamel' => { 'pet' => 'Azrael', } + * 'gargamel' => { 'pet' => 'Azrael', }, + * '' => { 'creator' => 'Pierre', 'country' => 'BE', }, * } * * creates a file with the contents * + * country = BE + * creator = Pierre + * * [gargamel] * pet = Azrael * * [smurfs] * colour = blue * population = 99 + * + * Note in particular the header-less "global" section first in the file. */ define cfgfile::ini_file( diff --git a/templates/ini_file.erb b/templates/ini_file.erb index 0c5d6f48db8655cda46a9c7f8f065f8950c039b0..96f148da6bf0e0396e299a0a75fe724fc662d275 100644 --- a/templates/ini_file.erb +++ b/templates/ini_file.erb @@ -4,9 +4,12 @@ # -%> <% - # Sort sections named "default" (case in-sensitive) before others + # Sort sections named "default" (case in-sensitive) and empty string + # ("global" section) before others. Empty string will always be sorted + # first, which is required for the "global" section, as such a section + # will not have a header. sorted_sections = @settings.keys().select { |k| - k.downcase() == 'default' + k == '' or k.downcase() == 'default' }.sort() sorted_sections += @settings.keys().reject { |k| sorted_sections.include?(k) @@ -18,7 +21,11 @@ sorted_sections.each do |section_name| section_vars = @settings[section_name] -%> +<% # Empty section name is "global" section without section header + if section_name != '' +-%> [<%= section_name %>] +<% end -%> <% # Find longest name, but only among those max 22 characters long shortnames = section_vars.keys().select { |name| name.length() <= 22 }