Puppet 4.0 and 4.1 are affected by PUP-4709 which raises duplicate
resource errors when using create_ini_settings(), due to the inclusion
of square brackets in the resource titles.
Error while evaluating a Function Call, Duplicate
declaration: Ini_setting[[foo] bar] is already declared; cannot
redeclare
Removing these from the function allows it to work on these Puppet
versions without error.
type file
show_diff => true (default) prints diff to logs
show_diff => md5 prints only md5 hashes instead of actual values
show_diff => false redacts any information about values
Global show_diff config takes priotiry over this one.
This added functionality allows you to specify hashes for ini_setting
and ini_subsetting so that they might be stored in Hiera. Without this
patch, you need to use ini_setting and ini_subsetting resources strictly
in code whereas with this patch, you could describe this in Hiera.
Currently the create_ini_settings function creates an ini_setting with a
title comprised of the section and setting names. This means that we
run into resource conflicts when defining the same section/setting
combinations but in different files. Since the path parameter is
required, we can safely add this to the title of the ini_setting
resource created by the create_ini_settings function. This commit does
just that.
Previously, trying to use a space as a key_val_separator in the ini_setting
type would fail because #strip is being called on the key_val_separator
attribute, which completely kills the space. This commit checks to see
if key_val_separator has been set as a space, and, if so, sets the `k_v_s`
variable in the library to be ' ' instead of ''. This in turn allows the
provider to check for existing values (instead of inserting the value every
time Puppet is run).
The previous match for \s would also match on newlines. This caused
existing settings with blank values to have the newline considered part
of the whitespace surrounding the separator. When such settings are
set with a value, the value ends up on the next line.
Also adding acceptance test for this particular situation.
create_ini_settings is a function that allows you to create
ini_setting resources from a simple hash:
$settings = { section1 => {
setting1 => val1
},
section2 => {
setting2 => val2,
setting3 => {
ensure => absent
}
}
}
$defaults = {
path => '/tmp/foo.ini'
}
create_ini_settings($settings,$defaults)
Will create the following resources
ini_setting{'[section1] setting1':
ensure => present,
section => 'section1',
setting => 'setting1',
value => 'val1',
path => '/tmp/foo.ini',
}
ini_setting{'[section2] setting2':
ensure => present,
section => 'section2',
setting => 'setting2',
value => 'val2',
path => '/tmp/foo.ini',
}
ini_setting{'[section2] setting3':
ensure => absent,
section => 'section2',
setting => 'setting3',
path => '/tmp/foo.ini',
}
This allows one to create much easier classes
that should be able to manage an arbritary set of
ini-style settings without having to specify each
one of them.
Noticed this when I was testing the module out with a FreeBSD host this code duplicates the shared_example used in the rest of the spec, so I DRY'd it up! 👍
We have many ini-style configuration files which use : as key value
separator. We'd like to be able to manage them with ini_setting as well.
This here is a naïve first attempt in that direction.
Please note that despite the fact that this *should* match, it's failing
unit tests.. This is a work in progress.
This should fix the build.
If this change isn't desired,
./spec/unit/puppet/provider/ini_setting/ruby_spec.rb:1044 could be
changed to:
```ruby
provider.exists?.should be_nil
```
The section name appears on a line by itself, in square brackets (`[` and
`]`), all characters between the opening `[` and the closing `]` should
be considered to form the section name.
Replace with `be true` and `be false` and make predicate return a
boolean.
> Methods that don't return a boolean, shouldn't end in a question mark.
-- https://github.com/bbatsov/ruby-style-guide#naming