Skip to content

Commit a44cf3e

Browse files
committed
Merge pull request #302 from 3flex/update-readme
(MODULES-927) Update readme
2 parents c1ff630 + b2033a0 commit a44cf3e

File tree

1 file changed

+180
-12
lines changed

1 file changed

+180
-12
lines changed

README.markdown

Lines changed: 180 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,43 @@ Returns the absolute value of a number, for example -34.56 becomes
7777

7878
- *Type*: rvalue
7979

80+
anchor
81+
------
82+
A simple resource type intended to be used as an anchor in a composite class.
83+
84+
In Puppet 2.6, when a class declares another class, the resources in the
85+
interior class are not contained by the exterior class. This interacts badly
86+
with the pattern of composing complex modules from smaller classes, as it
87+
makes it impossible for end users to specify order relationships between the
88+
exterior class and other modules.
89+
90+
The anchor type lets you work around this. By sandwiching any interior
91+
classes between two no-op resources that _are_ contained by the exterior
92+
class, you can ensure that all resources in the module are contained.
93+
94+
class ntp {
95+
# These classes will have the correct order relationship with each
96+
# other. However, without anchors, they won't have any order
97+
# relationship to Class['ntp'].
98+
class { 'ntp::package': }
99+
-> class { 'ntp::config': }
100+
-> class { 'ntp::service': }
101+
102+
# These two resources "anchor" the composed classes within the ntp
103+
# class.
104+
anchor { 'ntp::begin': } -> Class['ntp::package']
105+
Class['ntp::service'] -> anchor { 'ntp::end': }
106+
}
107+
108+
This allows the end user of the ntp module to establish require and before
109+
relationships with Class['ntp']:
110+
111+
class { 'ntp': } -> class { 'mcollective': }
112+
class { 'mcollective': } -> class { 'ntp': }
113+
114+
115+
- *Type*: resource
116+
80117
any2array
81118
---------
82119
This converts any object to an array containing that object. Empty argument
@@ -103,6 +140,19 @@ true, t, 1, y, and yes to 1
103140
Requires a single boolean or string as an input.
104141

105142

143+
- *Type*: rvalue
144+
145+
bool2str
146+
--------
147+
Converts a boolean to a string.
148+
Requires a single boolean as an input.
149+
150+
- *Type*: rvalue
151+
152+
camelcase
153+
---------
154+
Converts the case of a string or all strings in an array to camel case.
155+
106156
- *Type*: rvalue
107157

108158
capitalize
@@ -160,6 +210,23 @@ Count the number of elements in array that matches second argument.
160210
If called with only an array it counts the number of elements that are not nil/undef.
161211

162212

213+
- *Type*: rvalue
214+
215+
deep_merge
216+
----------
217+
Recursively merges two or more hashes together and returns the resulting hash.
218+
219+
*Example:*
220+
221+
$hash1 = {'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } }
222+
$hash2 = {'two' => 'dos', 'three' => { 'five' => 5 } }
223+
$merged_hash = deep_merge($hash1, $hash2)
224+
# The resulting hash is equivalent to:
225+
# $merged_hash = { 'one' => 1, 'two' => 'dos', 'three' => { 'four' => 4, 'five' => 5 } }
226+
227+
When there is a duplicate key that is a hash, they are recursively merged.
228+
When there is a duplicate key that is not a hash, the key in the rightmost hash will "win."
229+
163230
- *Type*: rvalue
164231

165232
defined_with_params
@@ -314,22 +381,54 @@ the type and parameters specified if it doesn't already exist.
314381

315382
file_line
316383
---------
317-
This resource ensures that a given line is contained within a file. You can also use
318-
"match" to replace existing lines.
384+
Ensures that a given line is contained within a file. The implementation
385+
matches the full line, including whitespace at the beginning and end. If
386+
the line is not contained in the given file, Puppet will add the line to
387+
ensure the desired state. Multiple resources may be declared to manage
388+
multiple lines in the same file.
319389

320390
*Examples:*
321391

322392
file_line { 'sudo_rule':
323393
path => '/etc/sudoers',
324394
line => '%sudo ALL=(ALL) ALL',
325395
}
326-
327-
file_line { 'change_mount':
328-
path => '/etc/fstab',
329-
line => '10.0.0.1:/vol/data /opt/data nfs defaults 0 0',
330-
match => '^172.16.17.2:/vol/old',
396+
file_line { 'sudo_rule_nopw':
397+
path => '/etc/sudoers',
398+
line => '%sudonopw ALL=(ALL) NOPASSWD: ALL',
331399
}
332400

401+
In this example, Puppet will ensure both of the specified lines are
402+
contained in the file /etc/sudoers.
403+
404+
*Parameters within `file_line`:*
405+
406+
**`after`**
407+
408+
An optional value used to specify the line after which we will add any new
409+
lines. (Existing lines are added in place)
410+
411+
**`line`**
412+
413+
The line to be appended to the file located by the path parameter.
414+
415+
**`match`**
416+
417+
An optional regular expression to run against existing lines in the file;
418+
if a match is found, we replace that line rather than adding a new line.
419+
420+
**`multiple`**
421+
422+
An optional value to determine if match can change multiple lines.
423+
424+
**`name`**
425+
426+
An arbitrary name used as the identity of the resource.
427+
428+
**`path`**
429+
430+
The file Puppet will ensure contains the line specified by the line parameter.
431+
333432
- *Type*: resource
334433

335434
flatten
@@ -713,6 +812,30 @@ failing that, will use a default value of 1.449.
713812

714813
- *Type*: rvalue
715814

815+
pick_default
816+
------------
817+
This function is similar to a coalesce function in SQL in that it will return
818+
the first value in a list of values that is not undefined or an empty string
819+
(two things in Puppet that will return a boolean false value). If no value is
820+
found, it will return the last argument.
821+
822+
Typically, this function is used to check for a value in the Puppet
823+
Dashboard/Enterprise Console, and failover to a default value like the
824+
following:
825+
826+
$real_jenkins_version = pick_default($::jenkins_version, '1.449')
827+
828+
The value of $real_jenkins_version will first look for a top-scope variable
829+
called 'jenkins_version' (note that parameters set in the Puppet Dashboard/
830+
Enterprise Console are brought into Puppet as top-scope variables), and,
831+
failing that, will use a default value of 1.449.
832+
833+
Note that, contrary to the pick() function, the pick_default does not fail if
834+
all arguments are empty. This allows pick_default to use an empty value as
835+
default.
836+
837+
- *Type*: rvalue
838+
716839
prefix
717840
------
718841
This function applies a prefix to all elements in an array.
@@ -749,6 +872,13 @@ Will return: ["a","b","c"]
749872

750873
Will return: ["host01", "host02", ..., "host09", "host10"]
751874

875+
Passing a third argument will cause the generated range to step by that
876+
interval, e.g.
877+
878+
range("0", "9", "2")
879+
880+
Will return: [0,2,4,6,8]
881+
752882
- *Type*: rvalue
753883

754884
reject
@@ -1166,6 +1296,43 @@ The following values will fail, causing compilation to abort:
11661296

11671297

11681298

1299+
- *Type*: statement
1300+
1301+
validate_ipv4_address
1302+
---------------------
1303+
Validate that all values passed are valid IPv4 addresses.
1304+
Fail compilation if any value fails this check.
1305+
1306+
The following values will pass:
1307+
1308+
$my_ip = "1.2.3.4"
1309+
validate_ipv4_address($my_ip)
1310+
validate_bool("8.8.8.8", "172.16.0.1", $my_ip)
1311+
1312+
The following values will fail, causing compilation to abort:
1313+
1314+
$some_array = [ 1, true, false, "garbage string", "3ffe:505:2" ]
1315+
validate_ipv4_address($some_array)
1316+
1317+
- *Type*: statement
1318+
1319+
validate_ipv6_address
1320+
---------------------
1321+
Validate that all values passed are valid IPv6 addresses.
1322+
Fail compilation if any value fails this check.
1323+
1324+
The following values will pass:
1325+
1326+
$my_ip = "3ffe:505:2"
1327+
validate_ipv6_address(1)
1328+
validate_ipv6_address($my_ip)
1329+
validate_bool("fe80::baf6:b1ff:fe19:7507", $my_ip)
1330+
1331+
The following values will fail, causing compilation to abort:
1332+
1333+
$some_array = [ true, false, "garbage string", "1.2.3.4" ]
1334+
validate_ipv6_address($some_array)
1335+
11691336
- *Type*: statement
11701337

11711338
validate_re
@@ -1200,21 +1367,22 @@ A helpful error message can be returned like this:
12001367
validate_slength
12011368
----------------
12021369
Validate that the first argument is a string (or an array of strings), and
1203-
less/equal to than the length of the second argument. It fails if the first
1204-
argument is not a string or array of strings, and if arg 2 is not convertable
1205-
to a number.
1370+
less/equal to than the length of the second argument. An optional third
1371+
parameter can be given a the minimum length. It fails if the first
1372+
argument is not a string or array of strings, and if arg 2 and arg 3 are
1373+
not convertable to a number.
12061374

12071375
The following values will pass:
12081376

12091377
validate_slength("discombobulate",17)
12101378
validate_slength(["discombobulate","moo"],17)
1379+
validate_slength(["discombobulate","moo"],17,3)
12111380

12121381
The following values will not:
12131382

12141383
validate_slength("discombobulate",1)
12151384
validate_slength(["discombobulate","thermometer"],5)
1216-
1217-
1385+
validate_slength(["discombobulate","moo"],17,10)
12181386

12191387
- *Type*: statement
12201388

0 commit comments

Comments
 (0)