Skip to content

Commit 43f0c68

Browse files
committed
Merge pull request redhat-openstack#180 from jbondpdx/1.4.x
Edits to new Function: `create_ini_settings` in README
2 parents f72730d + d9b4c36 commit 43f0c68

1 file changed

Lines changed: 137 additions & 136 deletions

File tree

README.markdown

Lines changed: 137 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ Many applications use INI-style configuration files to store their settings. Thi
2525

2626
###Beginning with inifile
2727

28-
2928
To manage a single setting in an INI file, add the `ini_setting` type to a class:
3029

31-
~~~
30+
~~~puppet
3231
ini_setting { "sample setting":
3332
ensure => present,
3433
path => '/tmp/foo.ini',
@@ -51,9 +50,12 @@ The inifile module tries hard not to manipulate your file any more than it needs
5150

5251
Use the `ini_subsetting` type:
5352

53+
~~~puppet
54+
JAVA_ARGS="-Xmx512m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/pe-puppetdb/puppetdb-oom.hprof"
5455
~~~
55-
JAVA_ARGS="-Xmx192m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/pe-puppetdb/puppetdb-oom.hprof "
5656

57+
58+
~~~puppet
5759
ini_subsetting {'sample subsetting':
5860
ensure => present,
5961
section => '',
@@ -67,11 +69,12 @@ ini_subsetting {'sample subsetting':
6769

6870
###Use a non-standard section header
6971

70-
~~~
72+
~~~puppet
7173
default:
7274
minage = 1
73-
maxage = 13
75+
~~~
7476

77+
~~~puppet
7578
ini_setting { 'default minage':
7679
ensure => present,
7780
path => '/etc/security/users',
@@ -85,7 +88,6 @@ ini_setting { 'default minage':
8588

8689
###Implement child providers
8790

88-
8991
You might want to create child providers that inherit the `ini_setting` provider, for one or both of these purposes:
9092

9193
* Make a custom resource to manage an application that stores its settings in INI files, without recreating the code to manage the files themselves.
@@ -94,7 +96,7 @@ You might want to create child providers that inherit the `ini_setting` provider
9496

9597
To implement child providers, first specify a custom type. Have it implement a namevar called `name` and a property called `value`:
9698

97-
~~~
99+
~~~ruby
98100
#my_module/lib/puppet/type/glance_api_config.rb
99101
Puppet::Type.newtype(:glance_api_config) do
100102
ensurable
@@ -114,7 +116,7 @@ end
114116

115117
Your type also needs a provider that uses the `ini_setting` provider as its parent:
116118

117-
~~~
119+
~~~ruby
118120
# my_module/lib/puppet/provider/glance_api_config/ini_setting.rb
119121
Puppet::Type.type(:glance_api_config).provide(
120122
:ini_setting,
@@ -138,20 +140,128 @@ end
138140

139141
Now the settings in /etc/glance/glance-api.conf file can be managed as individual resources:
140142

141-
~~~
143+
~~~puppet
142144
glance_api_config { 'HEADER/important_config':
143145
value => 'secret_value',
144146
}
145147
~~~
146148

147149
If you've implemented self.file_path, you can have Puppet purge the file of all lines that aren't implemented as Puppet resources:
148150

149-
~~~
151+
~~~puppet
150152
resources { 'glance_api_config'
151153
purge => true,
152154
}
153155
~~~
154156

157+
### Manage multiple ini_settings
158+
159+
To manage multiple ini_settings, use the [`create_ini_settings`](#function-create_ini_settings) function.
160+
161+
~~~puppet
162+
$defaults = { 'path' => '/tmp/foo.ini' }
163+
$example = { 'section1' => { 'setting1' => 'value1' } }
164+
create_ini_settings($example, $defaults)
165+
~~~
166+
167+
results in:
168+
169+
~~~puppet
170+
ini_setting { '[section1] setting1':
171+
ensure => present,
172+
section => 'section1',
173+
setting => 'setting1',
174+
value => 'value1',
175+
path => '/tmp/foo.ini',
176+
}
177+
~~~
178+
179+
To include special parameters, the following code:
180+
181+
~~~puppet
182+
$defaults = { 'path' => '/tmp/foo.ini' }
183+
$example = {
184+
'section1' => {
185+
'setting1' => 'value1',
186+
'settings2' => {
187+
'ensure' => 'absent'
188+
}
189+
}
190+
}
191+
create_ini_settings($example, $defaults)
192+
~~~
193+
194+
results in:
195+
196+
~~~puppet
197+
ini_setting { '[section1] setting1':
198+
ensure => present,
199+
section => 'section1',
200+
setting => 'setting1',
201+
value => 'value1',
202+
path => '/tmp/foo.ini',
203+
}
204+
ini_setting { '[section1] setting2':
205+
ensure => absent,
206+
section => 'section1',
207+
setting => 'setting2',
208+
path => '/tmp/foo.ini',
209+
}
210+
~~~
211+
212+
#### Manage multiple ini_settings with Hiera
213+
214+
This example requires Puppet 3.x/4.x, as it uses automatic retrieval of Hiera data for class parameters and `puppetlabs/stdlib`.
215+
216+
For the profile `example`:
217+
218+
~~~puppet
219+
class profile::example (
220+
$settings,
221+
) {
222+
validate_hash($settings)
223+
$defaults = { 'path' => '/tmp/foo.ini' }
224+
create_ini_settings($settings, $defaults)
225+
}
226+
~~~
227+
228+
Provide this in your Hiera data:
229+
230+
~~~puppet
231+
profile::example::settings:
232+
section1:
233+
setting1: value1
234+
setting2: value2
235+
setting3:
236+
ensure: absent
237+
~~~
238+
239+
Results in:
240+
241+
~~~puppet
242+
ini_setting { '[section1] setting1':
243+
ensure => present,
244+
section => 'section1',
245+
setting => 'setting1',
246+
value => 'value1',
247+
path => '/tmp/foo.ini',
248+
}
249+
ini_setting { '[section1] setting2':
250+
ensure => present,
251+
section => 'section1',
252+
setting => 'setting2',
253+
value => 'value2',
254+
path => '/tmp/foo.ini',
255+
}
256+
ini_setting { '[section1] setting3':
257+
ensure => absent,
258+
section => 'section1',
259+
setting => 'setting3',
260+
path => '/tmp/foo.ini',
261+
}
262+
~~~
263+
264+
155265
##Reference
156266

157267
###Public Types
@@ -164,9 +274,6 @@ resources { 'glance_api_config'
164274

165275
* [`create_ini_settings`](#function-create_ini_settings)
166276

167-
168-
169-
170277
### Type: ini_setting
171278

172279
Manages a setting within an INI file.
@@ -207,12 +314,9 @@ Determines whether the specified setting should exist. Valid options: 'present'
207314

208315
##### `section_suffix`
209316

210-
*Optional.* Designates the string that will appear after the section's name. Default value: "]"
211-
212-
**NOTE:** The way this type finds all sections in the file is by looking for lines like `${section_prefix}${title}${section_suffix}`
213-
214-
317+
*Optional.* Designates the string that will appear after the section's name. Default value: "]".
215318

319+
**NOTE:** This type finds all sections in the file by looking for lines like `${section_prefix}${title}${section_suffix}`.
216320

217321
### Type: ini_subsetting
218322

@@ -248,7 +352,6 @@ Specifies whether the subsetting should be present. Valid options: 'present' and
248352

249353
*Required.* Designates a subsetting to manage within the specified setting. Valid options: a string.
250354

251-
252355
##### `subsetting_separator`
253356

254357
*Optional.* Specifies a string to use between subsettings. Valid options: a string. Default value: " ".
@@ -257,142 +360,40 @@ Specifies whether the subsetting should be present. Valid options: 'present' and
257360

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

260-
261-
262-
263363
### Function: create_ini_settings
264364

265-
`create_ini_settings($settings, $defaults)`
365+
Manages multiple `ini_setting` resources from a hash. Note that this cannot be used with ini_subsettings.
266366

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!
367+
`create_ini_settings($settings, $defaults)`
268368

269-
#### Parameters
369+
#### Arguments
270370

271-
##### `$settings`
371+
##### First argument: `settings`
272372

273-
*Required.* Specify a hash with the ini_setting resources.
373+
*Required.* Specify a hash representing the `ini_setting` resources you want to create.
274374

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-
~~~
375+
##### Second argument: `defaults`
291376

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',
377+
*Optional.* Accepts a hash to be used as the values for any attributes not defined in the first argument.
378+
379+
~~~puppet
380+
$example = {
381+
'section1' => {
382+
'setting1' => {
383+
'value' => 'value1', 'path' => '/tmp/foo.ini'
384+
}
385+
}
318386
}
319387
~~~
320388

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-
332389
Default value: '{}'.
333390

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-
388391
##Limitations
389392

390393
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.
391394

392395
##Development
393396

394-
#Development
395-
396397
Puppet Labs modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can't access the huge number of platforms and myriad of hardware, software, and deployment configurations that Puppet is intended to serve.
397398

398399
We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.

0 commit comments

Comments
 (0)