##Overview
-Adds a standard library of resources for Puppet modules.
+Adds a standard library of resources for Puppet modules.
##Module Description
* Defined resource types
* 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
-### Classes
+### Classes
#### Public Classes
class { java: stage => 'runtime' }
}
```
-
+
### 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`: 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 => '%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.
* `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
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
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:
```
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
* `merge`: Merges two or more hashes together and returns the resulting hash.
*Example*:
-
+
```
$hash1 = {'one' => 1, 'two' => 2}
$hash2 = {'two' => 'dos', 'three' => 'tres'}
# 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
```
$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
```
Class foo::bar is private
```
-
+
You can specify the error message you want to use:
-
+
```
private("You're not supposed to do that!")
```
* `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"].
+
*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
* `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')
validate_absolute_path($undefined)
```
- *Type*: statement
+ *Type*: statement
-* `validate_array`: Validate that all passed values are array data structures. Abort catalog compilation if any value fails this check.
+* `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:
```
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:
```
* `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:
```
```
validate_cmd($sudoerscontent, '/usr/sbin/visudo -c -f', 'Visudo failed to validate sudoers content')
```
-
+
*Type*: statement
* `validate_hash`: Validates that all passed values are hash data structures. Abort catalog compilation if any value fails this check.
$undefined = undef
validate_hash($undefined)
```
-
+
*Type*: statement
* `validate_re`: Performs simple validation of a string against one or more regular expressions. The first argument of this function should be the string to
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')
```
* `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.
###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