summaryrefslogtreecommitdiff
path: root/README.markdown
diff options
context:
space:
mode:
Diffstat (limited to 'README.markdown')
-rw-r--r--README.markdown192
1 files changed, 114 insertions, 78 deletions
diff --git a/README.markdown b/README.markdown
index 69c5d3d..cbe42b4 100644
--- a/README.markdown
+++ b/README.markdown
@@ -1,7 +1,5 @@
#stdlib
-[![Build Status](https://travis-ci.org/puppetlabs/puppetlabs-stdlib.png?branch=master)](https://travis-ci.org/puppetlabs/puppetlabs-stdlib)
-
####Table of Contents
1. [Overview](#overview)
@@ -14,7 +12,7 @@
##Overview
-Adds a standard library of resources for Puppet modules.
+Adds a standard library of resources for Puppet modules.
##Module Description
@@ -28,19 +26,21 @@ modules. Puppet modules make heavy use of this standard library. The stdlib modu
* Types
* Providers
+> *Note:* As of version 3.7, Puppet Enterprise no longer includes the stdlib module. If you're running Puppet Enterprise, you should install the most recent release of stdlib for compatibility with Puppet modules.
+
##Setup
-Installing the stdlib module adds the functions, facts, and resources of this standard library to Puppet.
+Installing the stdlib module adds the functions, facts, and resources of this standard library to Puppet.
##Usage
-After you've installed stdlib, all of its functions, facts, and resources are available for module use or development.
+After you've installed stdlib, all of its functions, facts, and resources are available for module use or development.
-If you want to use a standardized set of run stages for Puppet, `include stdlib` in your manifest.
+If you want to use a standardized set of run stages for Puppet, `include stdlib` in your manifest.
-##Reference
+## Reference
-### Classes
+### Classes
#### Public Classes
@@ -74,6 +74,29 @@ If you want to use a standardized set of run stages for Puppet, `include stdlib`
}
```
+### Resources
+
+* `file_line`: This resource ensures that a given line, including whitespace at the beginning and end, is contained within a file. If the line is not contained in the given file, Puppet will add the line. Multiple resources can be declared to manage multiple lines in the same file. You can also use match to replace existing lines.
+
+ ```
+ file_line { 'sudo_rule':
+ path => '/etc/sudoers',
+ line => '%sudo ALL=(ALL) ALL',
+ }
+ file_line { 'sudo_rule_nopw':
+ path => '/etc/sudoers',
+ line => '%sudonopw ALL=(ALL) NOPASSWD: ALL',
+ }
+ ```
+
+ * `after`: Specify the line after which Puppet will add any new lines. (Existing lines are added in place.) Optional.
+ * `ensure`: Ensures whether the resource is present. Valid values are 'present', 'absent'.
+ * `line`: The line to be added to the file located by the `path` parameter.
+ * `match`: A regular expression to run against existing lines in the file; if a match is found, we replace that line rather than adding a new line. Optional.
+ * `multiple`: Determine if match can change multiple lines. Valid values are 'true', 'false'. Optional.
+ * `name`: An arbitrary name used as the identity of the resource.
+ * `path`: The file in which Puppet will ensure the line specified by the line parameter.
+
### Functions
* `abs`: Returns the absolute value of a number; for example, '-34.56' becomes '34.56'. Takes a single integer and float value as an argument. *Type*: rvalue
@@ -84,6 +107,13 @@ If you want to use a standardized set of run stages for Puppet, `include stdlib`
Requires an action ('encode', 'decode') and either a plain or base64-encoded
string. *Type*: rvalue
+* `basename`: Returns the `basename` of a path (optionally stripping an extension). For example:
+ * ('/path/to/a/file.ext') returns 'file.ext'
+ * ('relative/path/file.ext') returns 'file.ext'
+ * ('/path/to/a/file.ext', '.ext') returns 'file'
+
+ *Type*: rvalue
+
* `bool2num`: Converts a boolean to a number. Converts values:
* 'false', 'f', '0', 'n', and 'no' to 0.
* 'true', 't', '1', 'y', and 'yes' to 1.
@@ -92,12 +122,17 @@ string. *Type*: rvalue
* `capitalize`: Capitalizes the first letter of a string or array of strings.
Requires either a single string or an array as an input. *Type*: rvalue
+* `ceiling`: Returns the smallest integer greater than or equal to the argument.
+Takes a single numeric value as an argument. *Type*: rvalue
+
* `chomp`: Removes the record separator from the end of a string or an array of
strings; for example, 'hello\n' becomes 'hello'. Requires a single string or array as an input. *Type*: rvalue
* `chop`: Returns a new string with the last character removed. If the string ends with '\r\n', both characters are removed. Applying `chop` to an empty string returns an empty string. If you want to merely remove record separators, then you should use the `chomp` function. Requires a string or an array of strings as input. *Type*: rvalue
-* `concat`: Appends the contents of array 2 onto array 1. For example, `concat(['1','2','3'],'4')` results in: ['1','2','3','4']. *Type*: rvalue
+* `concat`: Appends the contents of multiple arrays onto array 1. For example:
+ * `concat(['1','2','3'],'4')` results in: ['1','2','3','4'].
+ * `concat(['1','2','3'],'4',['5','6','7'])` results in: ['1','2','3','4','5','6','7'].
* `count`: Takes an array as first argument and an optional second argument. Count the number of elements in array that matches second argument. If called with only an array, it counts the number of elements that are **not** nil/undef. *Type*: rvalue
@@ -112,11 +147,11 @@ strings; for example, 'hello\n' becomes 'hello'. Requires a single string or arr
user { 'dan': ensure => present, }
}
```
-
+
*Type*: rvalue
* `delete`: Deletes all instances of a given element from an array, substring from a
-string, or key from a hash. For example, `delete(['a','b','c','b'], 'b')` returns ['a','c']; `delete('abracadabra', 'bra')` returns 'acada'. *Type*: rvalue
+string, or key from a hash. For example, `delete(['a','b','c','b'], 'b')` returns ['a','c']; `delete('abracadabra', 'bra')` returns 'acada'. `delete({'a' => 1,'b' => 2,'c' => 3},['b','c'])` returns {'a'=> 1} *Type*: rvalue
* `delete_at`: Deletes a determined indexed value from an array. For example, `delete_at(['a','b','c'], 1)` returns ['a','c']. *Type*: rvalue
@@ -156,25 +191,6 @@ also appear in the second array. For example, `difference(["a","b","c"],["b","c"
*Type*: statement
-* `file_line`: This resource ensures that a given line is contained within a file. You can also use match to replace existing lines.
-
- *Example:*
-
- ```
- file_line { 'sudo_rule':
- path => '/etc/sudoers',
- line => '%sudo ALL=(ALL) ALL',
- }
-
- file_line { 'change_mount':
- path => '/etc/fstab',
- line => '10.0.0.1:/vol/data /opt/data nfs defaults 0 0',
- match => '^172.16.17.2:/vol/old',
- }
- ```
-
- *Type*: resource
-
* `flatten`: This function flattens any deeply nested arrays and returns a single flat array as a result. For example, `flatten(['a', ['b', ['c']]])` returns ['a','b','c']. *Type*: rvalue
* `floor`: Returns the largest integer less than or equal to the argument.
@@ -239,7 +255,7 @@ returns the value of the resource's parameter. For example, the following code r
has_interface_with("macaddress", "x:x:x:x:x:x")
has_interface_with("ipaddress", "127.0.0.1") => true
```
-
+
If no kind is given, then the presence of the interface is checked:
```
@@ -265,7 +281,7 @@ returns the value of the resource's parameter. For example, the following code r
notice('this will be printed')
}
```
-
+
*Type*: rvalue
* `hash`: This function converts an array into a hash. For example, `hash(['a',1,'b',2,'c',3])` returns {'a'=>1,'b'=>2,'c'=>3}. *Type*: rvalue
@@ -312,12 +328,12 @@ returns the value of the resource's parameter. For example, the following code r
* `max`: Returns the highest value of all arguments. Requires at least one argument. *Type*: rvalue
-* `member`: This function determines if a variable is a member of an array. For example, `member(['a','b'], 'b')` returns 'true', while `member(['a','b'], 'c')` returns 'false'. *Type*: rvalue
+* `member`: This function determines if a variable is a member of an array. The variable can be either a string, array, or fixnum. For example, `member(['a','b'], 'b')` and `member(['a','b','c'], ['b','c'])` return 'true', while `member(['a','b'], 'c')` and `member(['a','b','c'], ['c','d'])` return 'false'. *Type*: rvalue
* `merge`: Merges two or more hashes together and returns the resulting hash.
*Example*:
-
+
```
$hash1 = {'one' => 1, 'two' => 2}
$hash2 = {'two' => 'dos', 'three' => 'tres'}
@@ -325,7 +341,7 @@ returns the value of the resource's parameter. For example, the following code r
# The resulting hash is equivalent to:
# $merged_hash = {'one' => 1, 'two' => 'dos', 'three' => 'tres'}
```
-
+
When there is a duplicate key, the key in the rightmost hash "wins." *Type*: rvalue
* `min`: Returns the lowest value of all arguments. Requires at least one argument. *Type*: rvalue
@@ -341,10 +357,10 @@ returns the value of the resource's parameter. For example, the following code r
```
$real_jenkins_version = pick($::jenkins_version, '1.449')
```
-
+
*Type*: rvalue
-* `prefix`: This function applies a prefix to all elements in an array. For example, `prefix(['a','b','c'], 'p')` returns ['pa','pb','pc']. *Type*: rvalue
+* `prefix`: This function applies a prefix to all elements in an array or to the keys in a hash. For example, `prefix(['a','b','c'], 'p')` returns ['pa','pb','pc'], and `prefix({'a'=>'b','b'=>'c','c'=>'d'}, 'p')` returns {'pa'=>'b','pb'=>'c','pc'=>'d'}. *Type*: rvalue
* `private`: This function sets the current class or definition as private.
@@ -353,9 +369,9 @@ Calling the class or definition from outside the current module will fail. For e
```
Class foo::bar is private
```
-
+
You can specify the error message you want to use:
-
+
```
private("You're not supposed to do that!")
```
@@ -364,8 +380,10 @@ Calling the class or definition from outside the current module will fail. For e
* `range`: When given range in the form of '(start, stop)', `range` extrapolates a range as an array. For example, `range("0", "9")` returns [0,1,2,3,4,5,6,7,8,9]. Zero-padded strings are converted to integers automatically, so `range("00", "09")` returns [0,1,2,3,4,5,6,7,8,9].
- Non-integer strings are accepted; `range("a", "c")` returns ["a","b","c"], and `range("host01", "host10")` returns ["host01", "host02", ..., "host09", "host10"].
-
+ Non-integer strings are accepted; `range("a", "c")` returns ["a","b","c"], and `range("host01", "host10")` returns ["host01", "host02", ..., "host09", "host10"].
+
+ Passing a third argument will cause the generated range to step by that interval, e.g. `range("0", "9", "2")` returns ["0","2","4","6","8"]
+
*Type*: rvalue
* `reject`: This function searches through an array and rejects all elements that match the provided regular expression. For example, `reject(['aaa','bbb','ccc','aaaddd'], 'aaa')` returns ['bbb','ccc']. *Type*: rvalue
@@ -390,7 +408,7 @@ manifests as a valid password attribute. *Type*: rvalue
* `strftime`: This function returns formatted time. For example, `strftime("%s")` returns the time since epoch, and `strftime("%Y=%m-%d")` returns the date. *Type*: rvalue
*Format:*
-
+
* `%a`: The abbreviated weekday name ('Sun')
* `%A`: The full weekday name ('Sunday')
* `%b`: The abbreviated month name ('Jan')
@@ -437,7 +455,6 @@ manifests as a valid password attribute. *Type*: rvalue
* `%Z`: Time zone name
* `%%`: Literal '%' character
-
* `strip`: This function removes leading and trailing whitespace from a string or from every string inside an array. For example, `strip(" aaa ")` results in "aaa". *Type*: rvalue
* `suffix`: This function applies a suffix to all elements in an array. For example, `suffix(['a','b','c'], 'p')` returns ['ap','bp','cp']. *Type*: rvalue
@@ -449,7 +466,12 @@ manifests as a valid password attribute. *Type*: rvalue
* `to_bytes`: Converts the argument into bytes, for example 4 kB becomes 4096.
Takes a single string value as an argument. *Type*: rvalue
-* `type`: Returns the type when passed a variable. Type can be a string, array, hash, float, integer, or boolean. *Type*: rvalue
+* `type3x`: Returns a string description of the type when passed a value. Type can be a string, array, hash, float, integer, or boolean. This function will be removed when puppet 3 support is dropped and the new type system may be used. *Type*: rvalue
+
+* `type_of`: Returns the literal type when passed a value. Requires the new
+ parser. Useful for comparison of types with `<=` such as in `if
+ type_of($some_value) <= Array[String] { ... }` (which is equivalent to `if
+ $some_value =~ Array[String] { ... }`) *Type*: rvalue
* `union`: This function returns a union of two arrays. For example, `union(["a","b","c"],["b","c","d"])` returns ["a","b","c","d"].
@@ -457,33 +479,40 @@ Takes a single string value as an argument. *Type*: rvalue
You can also use this with arrays. For example, `unique(["a","a","b","b","c","c"])` returns ["a","b","c"]. *Type*: rvalue
-* `upcase`: Converts a string or an array of strings to uppercase. For example, `upcase("abcd")` returns 'ABCD'. *Type*: rvalue
+* `upcase`: Converts an object, array or hash of objects that respond to upcase to uppercase. For example, `upcase("abcd")` returns 'ABCD'. *Type*: rvalue
* `uriescape`: Urlencodes a string or array of strings. Requires either a single string or an array as an input. *Type*: rvalue
-* `validate_absolute_path`: Validate that the string represents an absolute path in the filesystem. This function works for Windows and Unix-style paths.
- The following values will pass:
+* `validate_absolute_path`: Validate the string represents an absolute path in the filesystem. This function works for Windows and Unix style paths.
- ```
- $my_path = "C:/Program Files (x86)/Puppet Labs/Puppet"
- validate_absolute_path($my_path)
- $my_path2 = "/var/lib/puppet"
- validate_absolute_path($my_path2)
- ```
+ The following values will pass:
- The following values will fail, causing compilation to abort:
+ ```
+ $my_path = 'C:/Program Files (x86)/Puppet Labs/Puppet'
+ validate_absolute_path($my_path)
+ $my_path2 = '/var/lib/puppet'
+ validate_absolute_path($my_path2)
+ $my_path3 = ['C:/Program Files (x86)/Puppet Labs/Puppet','C:/Program Files/Puppet Labs/Puppet']
+ validate_absolute_path($my_path3)
+ $my_path4 = ['/var/lib/puppet','/usr/share/puppet']
+ validate_absolute_path($my_path4)
+ ```
- ```
- validate_absolute_path(true)
- validate_absolute_path([ 'var/lib/puppet', '/var/foo' ])
- validate_absolute_path([ '/var/lib/puppet', 'var/foo' ])
- $undefined = undef
- validate_absolute_path($undefined)
- ```
-
- *Type*: statement
+ The following values will fail, causing compilation to abort:
+
+ ```
+ validate_absolute_path(true)
+ validate_absolute_path('../var/lib/puppet')
+ validate_absolute_path('var/lib/puppet')
+ validate_absolute_path([ 'var/lib/puppet', '/var/foo' ])
+ validate_absolute_path([ '/var/lib/puppet', 'var/foo' ])
+ $undefined = undef
+ validate_absolute_path($undefined)
+ ```
-* `validate_array`: Validate that all passed values are array data structures. Abort catalog compilation if any value fails this check.
+ *Type*: statement
+
+* `validate_array`: Validate that all passed values are array data structures. Abort catalog compilation if any value fails this check.
The following values will pass:
@@ -513,13 +542,13 @@ The first argument of this function should be the string to test, and the second
```
validate_augeas($passwdcontent, 'Passwd.lns', ['$file/foo'])
```
-
+
To ensure that no users use the '/bin/barsh' shell:
```
validate_augeas($passwdcontent, 'Passwd.lns', ['$file/*[shell="/bin/barsh"]']
```
-
+
You can pass a fourth argument as the error message raised and shown to the user:
```
@@ -531,13 +560,13 @@ The first argument of this function should be the string to test, and the second
* `validate_bool`: Validate that all passed values are either true or false. Abort catalog compilation if any value fails this check.
The following values will pass:
-
+
```
$iamtrue = true
validate_bool(true)
validate_bool(true, true, false, $iamtrue)
```
-
+
The following values will fail, causing compilation to abort:
```
@@ -549,14 +578,19 @@ The first argument of this function should be the string to test, and the second
*Type*: statement
-* `validate_cmd`: Performs validation of a string with an external command. The first argument of this function should be the string to test, and the second argument should be the path to a test command taking a file as last argument. If the command, launched against a tempfile containing the passed string, returns a non-null value, compilation aborts with a parse error.
+* `validate_cmd`: Performs validation of a string with an external command. The first argument of this function should be a string to test, and the second argument should be a path to a test command taking a % as a placeholder for the file path (will default to the end of the command if no % placeholder given). If the command, launched against a tempfile containing the passed string, returns a non-null value, compilation will abort with a parse error.
- You can pass a third argument as the error message raised and shown to the user:
+If a third argument is specified, this will be the error message raised and seen by the user.
```
+ # Defaults to end of path
validate_cmd($sudoerscontent, '/usr/sbin/visudo -c -f', 'Visudo failed to validate sudoers content')
```
-
+ ```
+ # % as file location
+ validate_cmd($haproxycontent, '/usr/sbin/haproxy -f % -c', 'Haproxy failed to validate config content')
+ ```
+
*Type*: statement
* `validate_hash`: Validates that all passed values are hash data structures. Abort catalog compilation if any value fails this check.
@@ -576,7 +610,7 @@ The first argument of this function should be the string to test, and the second
$undefined = undef
validate_hash($undefined)
```
-
+
*Type*: statement
* `validate_integer`: Validate that the first argument is an integer (or an array of integers). Abort catalog compilation if any of the checks fail.
@@ -669,8 +703,8 @@ of the regular expressions match the string passed in, compilation aborts with a
validate_re('one', [ '^two', '^three' ])
```
- To set the error message:
-
+ To set the error message:
+
```
validate_re($::puppetversion, '^2.7', 'The $puppetversion fact value does not match 2.7')
```
@@ -680,19 +714,19 @@ of the regular expressions match the string passed in, compilation aborts with a
* `validate_slength`: Validates that the first argument is a string (or an array of strings), and is less than or equal to the length of the second argument. It fails if the first argument is not a string or array of strings, or if arg 2 is not convertable to a number.
The following values pass:
-
+
```
validate_slength("discombobulate",17)
validate_slength(["discombobulate","moo"],17)
```
-
+
The following values fail:
```
validate_slength("discombobulate",1)
validate_slength(["discombobulate","thermometer"],5)
```
-
+
*Type*: statement
* `validate_string`: Validates that all passed values are string data structures. Aborts catalog compilation if any value fails this check.
@@ -746,9 +780,11 @@ of the regular expressions match the string passed in, compilation aborts with a
##Limitations
+As of Puppet Enterprise version 3.7, the stdlib module is no longer included in PE. PE users should install the most recent release of stdlib for compatibility with Puppet modules.
+
###Version Compatibility
-Versions | Puppet 2.6 | Puppet 2.7 | Puppet 3.x | Puppet 4.x |
+Versions | Puppet 2.6 | Puppet 2.7 | Puppet 3.x | Puppet 4.x |
:---------------|:-----:|:---:|:---:|:----:
**stdlib 2.x** | **yes** | **yes** | no | no
**stdlib 3.x** | no | **yes** | **yes** | no