'How to include multiple values under a section in inifile

I am trying to create a puppet manifest using inifile. This would be for a configuration file where I need to have the following format.

[safe]
    directory = /home/foo
    directory = /home/test
    directory = /home/something

I know that there is a way to use directory1, and directory2 but I was wondering if there is a way to do it without changing the directory since it needs that specific attribute. This implementation is meant for puppet manifest. Also, I was thinking puppetlabs/inifile module but if there is another option to achieve this would be great too.

Thanks for the help in advance

So far, I have an implementation like:

ini_setting { 'procedure cache size':
  ensure         => present,
  path           => '/var/lib/somethning/test.config',
  section        => 'safe',
  setting        => 'directory',
  value          => '/home/foo',
  indent_char    => "\t",
}

This is for each directory. The purpose for this implementation is to address the new git configuration for safe.repository in the recent update. My understanding is that for multiple directories, it adds a new value as directory = <directory> I don't believe that it likes directories separate by commas.



Solution 1:[1]

First I thought about file_line, but this is not idempotent for multi-line settings (you get problems when you run again). You can try: Sample puppet code dir.pp

$safe_directories="directory = /home/foo
directory = /home/test
directory = /home/something"
    
notice "Testing\n${safe_directories}"
    
file { "/tmp/result.ini":
  ensure => present,
  content => template('/tmp/layout.erb'),
}

notice "Check /tmp/result.ini"

Sample template /tmp/layout.erb

[unsafe]
  directory=/unsafe
[safe]
  <%=@safe_directories%>
  otherfield=secure
[header3]
  nothing = here

Now run command from commandline

puppet apply dir.pp

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Walter A