Skip to content

Commit 7a45b38

Browse files
committed
Merge pull request #173 from poikilotherm/fix/master/add_create_ini_settings_to_readme
MODULES-2158: Add documentation for create_ini_settings() to README
2 parents 9fc499b + d3724aa commit 7a45b38

1 file changed

Lines changed: 138 additions & 1 deletion

File tree

README.markdown

Lines changed: 138 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ resources { 'glance_api_config'
160160

161161
* [`ini_subsetting`](#type-ini_subsetting)
162162

163+
###Public Functions
164+
165+
* [`create_ini_settings`](#function-create_ini_settings)
166+
167+
168+
169+
163170
### Type: ini_setting
164171

165172
Manages a setting within an INI file.
@@ -204,9 +211,11 @@ Determines whether the specified setting should exist. Valid options: 'present'
204211

205212
**NOTE:** The way this type finds all sections in the file is by looking for lines like `${section_prefix}${title}${section_suffix}`
206213

207-
### Type: ini_subsetting
208214

209215

216+
217+
### Type: ini_subsetting
218+
210219
Manages multiple values within the same INI setting.
211220

212221
#### Parameters
@@ -248,6 +257,134 @@ Specifies whether the subsetting should be present. Valid options: 'present' and
248257

249258
*Optional.* Supplies a value for the specified subsetting. Valid options: a string. Default value: undefined.
250259

260+
261+
262+
263+
### Function: create_ini_settings
264+
265+
`create_ini_settings($settings, $defaults)`
266+
267+
Manage multiple ini_setting resources from a hash with comfort. You can provide a hash in your manifest and feed it from Hiera. This can however not be used with ini_subsettings!
268+
269+
#### Parameters
270+
271+
##### `$settings`
272+
273+
*Required.* Specify a hash with the ini_setting resources.
274+
275+
###### Example
276+
~~~
277+
defaults = { 'path' => '/tmp/foo.ini' }
278+
$example = { 'section1' => { 'setting1' => 'value1' } }
279+
create_ini_settings($example, $defaults)
280+
~~~
281+
results in a resource
282+
~~~
283+
ini_setting { '[section1] setting1':
284+
ensure => present,
285+
section => 'section1',
286+
setting => 'setting1',
287+
value => 'value1',
288+
path => '/tmp/foo.ini'
289+
}
290+
~~~
291+
292+
###### Example with special parameters
293+
~~~
294+
defaults = { 'path' => '/tmp/foo.ini' }
295+
$example = { 'section1' => {
296+
'setting1' => 'value1',
297+
'settings2' => {
298+
'ensure' => 'absent'
299+
}
300+
}
301+
}
302+
create_ini_settings($example, $defaults)
303+
~~~
304+
results in resources
305+
~~~
306+
ini_setting { '[section1] setting1':
307+
ensure => present,
308+
section => 'section1',
309+
setting => 'setting1',
310+
value => 'value1',
311+
path => '/tmp/foo.ini',
312+
}
313+
ini_setting { '[section1] setting2':
314+
ensure => absent,
315+
section => 'section1',
316+
setting => 'setting2',
317+
path => '/tmp/foo.ini',
318+
}
319+
~~~
320+
321+
##### `$defaults`
322+
323+
*Optional, but recommended.*
324+
325+
This works exactly like `create_resources` defaults parameter. Use it to not repeat yourself to often
326+
and write settings more densely. Example usage see parameter `$settings` above.
327+
328+
If you omit this parameter, you will need to add the `path` and `value` attribute to every single setting as a hash
329+
(`$example = { 'section1' => { 'setting1' => { 'value' => 'value1', 'path' => '/tmp/foo.ini' } } }`).
330+
This most certainly is not what you want, but if you need it it's there.
331+
332+
Default value: '{}'.
333+
334+
#### Example with Hiera
335+
This example will need Puppet 3.x/4.x as it uses automatic retrieval of Hiera data for class parameters and
336+
`puppetlabs/stdlib` (you use that one already, don't you?).
337+
338+
Of course you may use `hiera_hash` when on Puppet 2.x or other use cases. Remember this is only one example,
339+
feel free to live your creativity on writing manifests.
340+
341+
Imagine a profile `example`:
342+
~~~
343+
class profile::example (
344+
$settings,
345+
) {
346+
validate_hash($settings)
347+
$defaults = { 'path' => '/tmp/foo.ini' }
348+
create_ini_settings($settings, $defaults)
349+
}
350+
~~~
351+
352+
Now provide this in your Hiera data:
353+
~~~
354+
profile::example::settings:
355+
section1:
356+
setting1: value1
357+
setting2: value2
358+
setting3:
359+
ensure: absent
360+
~~~
361+
362+
This will result in resources:
363+
~~~
364+
ini_setting { '[section1] setting1':
365+
ensure => present,
366+
section => 'section1',
367+
setting => 'setting1',
368+
value => 'value1',
369+
path => '/tmp/foo.ini',
370+
}
371+
ini_setting { '[section1] setting2':
372+
ensure => present,
373+
section => 'section1',
374+
setting => 'setting2',
375+
value => 'value2',
376+
path => '/tmp/foo.ini',
377+
}
378+
ini_setting { '[section1] setting3':
379+
ensure => absent,
380+
section => 'section1',
381+
setting => 'setting3',
382+
path => '/tmp/foo.ini',
383+
}
384+
~~~
385+
386+
387+
251388
##Limitations
252389

253390
This module has been tested on [all PE-supported platforms](https://forge.puppetlabs.com/supported#compat-matrix), and no issues have been identified. Additionally, it is tested (but not supported) on Windows 7, Mac OS X 10.9, and Solaris 12.

0 commit comments

Comments
 (0)