From 89995e4db0eacf55260cf5ca85e715e2e45dfce5 Mon Sep 17 00:00:00 2001 From: Oliver Bertuch Date: Tue, 25 Nov 2014 12:45:23 +0100 Subject: Allow array of pathes in validate_absolute_path --- README.markdown | 49 ++++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) (limited to 'README.markdown') diff --git a/README.markdown b/README.markdown index 78839c6..957be9b 100644 --- a/README.markdown +++ b/README.markdown @@ -461,27 +461,34 @@ You can also use this with arrays. For example, `unique(["a","a","b","b","c","c" * `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: - - ``` - $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 fail, causing compilation to abort: - - ``` - 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 +* `validate_absolute_path`: Validate the string represents an absolute path in the filesystem. This function works for Windows and Unix style paths. + + The following values will pass: + + ``` + $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) + ``` + + 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) + ``` + + *Type*: statement * `validate_array`: Validate that all passed values are array data structures. Abort catalog compilation if any value fails this check. -- cgit v1.2.3 From 294b8b572dfeb14555c40737eed2491e7837ef29 Mon Sep 17 00:00:00 2001 From: jbondpdx Date: Tue, 25 Nov 2014 11:32:12 -0800 Subject: Added a note that stdlib no longer ships with PE 3.7+ Users didn't realize we stopped shipping stdlib module with PE. I added this information to the stdlib readme. --- README.markdown | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'README.markdown') diff --git a/README.markdown b/README.markdown index 78839c6..b7824ff 100644 --- a/README.markdown +++ b/README.markdown @@ -27,6 +27,8 @@ modules. Puppet modules make heavy use of this standard library. The stdlib modu * 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 @@ -676,6 +678,8 @@ 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 | -- cgit v1.2.3 From ef3d42f7bbdf95b21f46e580de309298cad300ea Mon Sep 17 00:00:00 2001 From: Rob Fugina Date: Mon, 17 Nov 2014 16:01:42 -0600 Subject: Added basename() based on Ruby's File.basename Based on dirname code. Includes RSpec tests and docs. --- README.markdown | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'README.markdown') diff --git a/README.markdown b/README.markdown index 78839c6..67ef313 100644 --- a/README.markdown +++ b/README.markdown @@ -84,6 +84,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. -- cgit v1.2.3 From f6e20d20684f315d746e99ff554a0bdc714f96a3 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Fri, 19 Dec 2014 10:41:07 -0800 Subject: Update docs to reflect new behavior of delete function taking array in second argument --- README.markdown | 74 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) (limited to 'README.markdown') diff --git a/README.markdown b/README.markdown index c4022c5..0c7b80a 100644 --- a/README.markdown +++ b/README.markdown @@ -14,7 +14,7 @@ ##Overview -Adds a standard library of resources for Puppet modules. +Adds a standard library of resources for Puppet modules. ##Module Description @@ -27,22 +27,22 @@ modules. Puppet modules make heavy use of this standard library. The stdlib modu * 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 @@ -75,11 +75,11 @@ If you want to use a standardized set of run stages for Puppet, `include stdlib` 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', @@ -90,7 +90,7 @@ If you want to use a standardized set of run stages for Puppet, `include stdlib` 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. @@ -98,7 +98,7 @@ If you want to use a standardized set of run stages for Puppet, `include stdlib` * `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 @@ -144,11 +144,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 @@ -252,7 +252,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: ``` @@ -278,7 +278,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 @@ -330,7 +330,7 @@ returns the value of the resource's parameter. For example, the following code r * `merge`: Merges two or more hashes together and returns the resulting hash. *Example*: - + ``` $hash1 = {'one' => 1, 'two' => 2} $hash2 = {'two' => 'dos', 'three' => 'tres'} @@ -338,7 +338,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 @@ -354,7 +354,7 @@ 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 @@ -366,9 +366,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!") ``` @@ -377,8 +377,8 @@ 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"]. + *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 @@ -403,7 +403,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') @@ -501,9 +501,9 @@ You can also use this with arrays. For example, `unique(["a","a","b","b","c","c" 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: @@ -533,13 +533,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: ``` @@ -551,13 +551,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: ``` @@ -576,7 +576,7 @@ The first argument of this function should be the string to test, and the second ``` 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. @@ -596,7 +596,7 @@ The first argument of this function should be the string to test, and the second $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 @@ -619,8 +619,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') ``` @@ -630,19 +630,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. @@ -700,7 +700,7 @@ As of Puppet Enterprise version 3.7, the stdlib module is no longer included in ###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 -- cgit v1.2.3 From c125a0899435b26f7823bdf3793b4aeb27f4a707 Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Fri, 19 Dec 2014 11:52:11 +0000 Subject: README fixes for recent merges * (MODULES-444) Update README for concat changes * (MODULES-1582) Update `validate_cmd` readme * Plus some Whitespace fixes --- README.markdown | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'README.markdown') diff --git a/README.markdown b/README.markdown index 0c7b80a..689660e 100644 --- a/README.markdown +++ b/README.markdown @@ -129,7 +129,9 @@ strings; for example, 'hello\n' becomes 'hello'. Requires a single string or arr * `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 @@ -569,13 +571,18 @@ 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 -- cgit v1.2.3 From 7c8ae311cade65e84df1054779a039ff906e630c Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Mon, 15 Dec 2014 16:11:10 -0800 Subject: (MODULES-1473) Deprecate type() function for new parser The `type()` function will cease to work on the new parser because 'type' is a reserved keyword. The `type3x()` function may be used to continue similar functionality, but will be deprecated in favor of the built-in typing system. The `type_of()` function has been included to introspect types in the new parser. --- README.markdown | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'README.markdown') diff --git a/README.markdown b/README.markdown index 689660e..e9a1f4e 100644 --- a/README.markdown +++ b/README.markdown @@ -464,7 +464,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"]. -- cgit v1.2.3