diff --git a/README.md b/README.md index 650cd9403..1aef30655 100644 --- a/README.md +++ b/README.md @@ -419,7 +419,7 @@ Valid values: A windows filepath. #### `Stdlib::Filesource` -Matches paths valid values for the source parameter of the puppet file type. +Matches paths valid values for the source parameter of the Puppet file type. Acceptable input example: @@ -739,6 +739,8 @@ Returns the default provider Puppet uses to manage services on this system #### `abs` +**Deprecated:** This function has been replaced with a built-in [`abs`](https://puppet.com/docs/puppet/latest/function.html#abs) function as of Puppet 6.0.0. + Returns the absolute value of a number. For example, '-34.56' becomes '34.56'. Argument: A single argument of either an integer or float value. @@ -749,6 +751,19 @@ Argument: A single argument of either an integer or float value. Converts any object to an array containing that object. Converts empty argument lists are to empty arrays. Hashes are converted to arrays of alternating keys and values. Arrays are not touched. +Since Puppet 5.0.0, you can create new values of almost any datatype using the type system — you can use the built-in [`Array.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-array-and-tuple) function to create a new Array: + + $hsh = {'key' => 42, 'another-key' => 100} + notice(Array($hsh)) + +Would notice `[['key', 42], ['another-key', 100]]` + +The Array data type also has a special mode to "create an array if not already an array": + + notice(Array({'key' => 42, 'another-key' => 100}, true)) + +Would notice `[{'key' => 42, 'another-key' => 100}]`, as the `true` flag prevents the hash from being transformed into an array. + *Type*: rvalue. #### `any2bool` @@ -762,6 +777,8 @@ Converts any object to a Boolean: * An undef value returns `false`. * Anything else returns `true`. +See the built-in [`Boolean.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-boolean) + *Type*: rvalue. #### `assert_private` @@ -784,7 +801,18 @@ Converts a string to and from base64 encoding. Requires an `action` ('encode', ' For backward compatibility, `method` is set as `default` if not specified. -*Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater. +> **Note**: This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater. + +Since Puppet 4.8.0, the `Binary` data type can be used to produce base 64 encoded strings. + +See the built-in [`String.new`](https://puppet.com/docs/puppet/latest/function.html#binary-value-to-string) and [`Binary.new`](https://puppet.com/docs/puppet/latest/function.html#creating-a-binary) functions. + +See the built-in [`binary_file`](https://puppet.com/docs/puppet/latest/function.html#binary_file) function for reading a file with binary (non UTF-8) content. + + # encode a string as if it was binary + $encodestring = String(Binary('thestring', '%s')) + # decode a Binary assuming it is an UTF-8 String + $decodestring = String(Binary("dGhlc3RyaW5n"), "%s") **Examples:** @@ -831,6 +859,12 @@ Converts a Boolean to a number. Converts values: Argument: a single Boolean or string as an input. +Since Puppet 5.0.0, you can create values for almost any datatype using the type system — you can use the built-in [`Numeric.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-numeric), [`Integer.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-integer), and [`Float.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-float) +functions to convert to numeric values: + + notice(Integer(false)) # Notices 0 + notice(Float(true)) # Notices 1.0 + *Type*: rvalue. #### `bool2str` @@ -847,10 +881,22 @@ bool2str(false, 't', 'f') => 'f' Arguments: Boolean. +Since Puppet 5.0.0, you can create new values for almost any +datatype using the type system — you can use the built-in +[`String.new`](https://puppet.com/docs/puppet/latest/function.html#boolean-to-string) +function to convert to String, with many different format options: + + notice(String(false)) # Notices 'false' + notice(String(true)) # Notices 'true' + notice(String(false, '%y')) # Notices 'yes' + notice(String(true, '%y')) # Notices 'no' + *Type*: rvalue. #### `camelcase` +**Deprecated:** This function has been replaced with a built-in [`camelcase`](https://puppet.com/docs/puppet/latest/function.html#camelcase) function as of Puppet 6.0.0. + Converts the case of a string or all strings in an array to CamelCase (mixed case). Arguments: Either an array or string. Returns the same type of argument as it received, but in CamelCase form. @@ -861,6 +907,8 @@ Arguments: Either an array or string. Returns the same type of argument as it re #### `capitalize` +**Deprecated:** This function has been replaced with a built-in [`capitalize`](https://puppet.com/docs/puppet/latest/function.html#capitalize) function as of Puppet 6.0.0. + Capitalizes the first character of a string or array of strings and lowercases the remaining characters of each string. Arguments: either a single string or an array as an input. *Type*: rvalue. @@ -869,6 +917,8 @@ Arguments: either a single string or an array as an input. *Type*: rvalue. #### `ceiling` +**Deprecated:** This function has been replaced with a built-in [`ceiling`](https://puppet.com/docs/puppet/latest/function.html#ceiling) function as of Puppet 6.0.0. + Returns the smallest integer greater than or equal to the argument. Arguments: A single numeric value. @@ -877,6 +927,8 @@ Arguments: A single numeric value. #### `chomp` +**Deprecated:** This function has been replaced with a built-in [`chomp`](https://puppet.com/docs/puppet/latest/function.html#chomp) function as of Puppet 6.0.0. + Removes the record separator from the end of a string or an array of strings; for example, 'hello\n' becomes 'hello'. Arguments: a single string or array. @@ -885,6 +937,8 @@ Arguments: a single string or array. #### `chop` +**Deprecated:** This function has been replaced with a built-in [`chop`](https://puppet.com/docs/puppet/latest/function.html#chop) function as of Puppet 6.0.0. + 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. To only remove record separators, use the `chomp` function. Arguments: A string or an array of strings as input. @@ -901,6 +955,10 @@ Keeps value within the range [Min, X, Max] by sort based on integer value (param Arguments: strings, arrays, or numerics. +Since Puppet 6.0.0, you can use built-in functions to get the same result: + + [$minval, $maxval, $value_to_clamp].sort[1] + *Type*: rvalue. #### `concat` @@ -910,6 +968,12 @@ Appends the contents of multiple arrays onto the first array given. For example: * `concat(['1','2','3'],'4')` returns ['1','2','3','4']. * `concat(['1','2','3'],'4',['5','6','7'])` returns ['1','2','3','4','5','6','7']. +Since Puppet 4.0, concatenation of arrays and merge of hashes can be done with the `+` operator, and appending can be done with the `<<` operator: + + ['1','2','3'] + ['4','5','6'] + ['7','8','9'] # returns ['1','2','3','4','5','6','7'] + [1, 2, 3] << 4 # returns [1, 2, 3, 4] + [1, 2, 3] << [4, 5] # returns [1, 2, 3, [4, 5]] + *Type*: rvalue. #### `convert_base` @@ -919,9 +983,30 @@ Converts a given integer or base 10 string representing an integer to a specifie * `convert_base(5, 2)` results in: '101' * `convert_base('254', '16')` results in: 'fe' +Since Puppet 4.5.0, this can be done with the built-in [`String.new`](https://puppet.com/docs/puppet/latest/function.html#integer-to-string) function, with various formatting options: + + $binary_repr = String(5, '%b') # results in "101" + $hex_repr = String(254, '%x') # results in "fe" + $hex_repr = String(254, '%#x') # results in "0xfe" + #### `count` -If called with only an array, counts the number of elements that are **not** nil or `undef`. If called with a second argument, counts the number of elements in an array that matches the second argument. +Takes an array as the first argument and an optional second argument. +It counts the number of elements in an array that is equal to the second argument. +If called with only an array, it counts the number of elements that are not nil/undef/empty-string. + +> **Note**: Equality is tested with a Ruby method. It is subject to what Ruby considers +to be equal. For strings, equality is case sensitive. + +In Puppet core, counting can be done using a combination of the built-in functions +[`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) (since Puppet 4.0.0) and +[`length`](https://puppet.com/docs/puppet/latest/function.html#length) (since Puppet 5.5.0, before that in stdlib). + +This example shows counting values that are not `undef`: + + notice([42, "hello", undef].filter |$x| { $x =~ NotUndef }.length) + +Would notice 2. *Type*: rvalue. @@ -972,6 +1057,24 @@ For example: * `delete({'a' => 1,'b' => 2,'c' => 3},['b','c'])` returns {'a'=> 1}. * `delete(['ab', 'b'], 'b')` returns ['ab']. +Since Puppet 4.0.0, the minus (`-`) operator deletes values from arrays and deletes keys from a hash: + + ['a', 'b', 'c', 'b'] - 'b' + # would return ['a', 'c'] + + {'a'=>1,'b'=>2,'c'=>3} - ['b','c']) + # would return {'a' => '1'} + +You can perform a global delete from a string with the built-in +[`regsubst`](https://puppet.com/docs/puppet/latest/function.html#regsubst) function. + + 'abracadabra'.regsubst(/bra/, '', 'G') + # would return 'acada' + +In general, the built-in +[`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function +can filter out entries from arrays and hashes based on a combination of keys and values. + *Type*: rvalue. #### `delete_at` @@ -980,6 +1083,19 @@ Deletes a determined indexed value from an array. For example: `delete_at(['a','b','c'], 1)` returns ['a','c']. +Since Puppet 4, this can be done with the built-in +[`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function: + + ['a', 'b', 'c'].filter |$pos, $val | { $pos != 1 } # returns ['a', 'c'] + ['a', 'b', 'c', 'd'].filter |$pos, $val | { $pos % 2 != 0 } # returns ['b', 'd'] + +Or, if you want to delete from the beginning or the end of the array — or from both ends at the same time — use the slice operator `[ ]`: + + $array[0, -1] # the same as all the values + $array[2, -1] # all but the first 2 elements + $array[0, -3] # all but the last 2 elements + $array[1, -2] # all but the first and last element + *Type*: rvalue. #### `delete_regex` @@ -996,6 +1112,12 @@ For example * `delete_regex(['abf', 'ab', 'ac'], '^ab.*')` returns ['ac']. * `delete_regex(['ab', 'b'], 'b')` returns ['ab']. +Since Puppet 4.0.0, the equivalent can be performed with the built-in +[`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function: + + ["aaa", "aba", "aca"].filter |$val| { $val !~ /b/ } + # Would return: ['aaa', 'aca'] + *Type*: rvalue. #### `delete_values` @@ -1006,6 +1128,12 @@ For example: * `delete_values({'a'=>'A','b'=>'B','c'=>'C','B'=>'D'}, 'B')` returns {'a'=>'A','c'=>'C','B'=>'D'} +Since Puppet 4.0.0, you can perform the equivalent with the built-in +[`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function: + + $array.filter |$val| { $val != 'B' } + $hash.filter |$key, $val| { $val != 'B' } + *Type*: rvalue. #### `delete_undef_values` @@ -1016,6 +1144,12 @@ For example: * `$hash = delete_undef_values({a=>'A', b=>'', c=>`undef`, d => false})` returns {a => 'A', b => '', d => false}. +Since Puppet 4.0.0, you can perform the equivalent with the built-in +[`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function: + + $array.filter |$val| { $val =~ NotUndef } + $hash.filter |$key, $val| { $val =~ NotUndef } + *Type*: rvalue. #### `deprecation` @@ -1063,6 +1197,11 @@ For example: * `difference(["a","b","c"],["b","c","d"])` returns ["a"]. +Since Puppet 4, the minus (`-`) operator in the Puppet language does the same: + + ['a', 'b', 'c'] - ['b', 'c', 'd'] + # would return ['a'] + *Type*: rvalue. #### `dig` @@ -1163,6 +1302,8 @@ See also [unix2dos](#unix2dos). #### `downcase` +**Deprecated:** This function has been replaced with a built-in [`downcase`](https://puppet.com/docs/puppet/latest/function.html#downcase) function as of Puppet 6.0.0. + Converts the case of a string or of all strings in an array to lowercase. *Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater. @@ -1294,6 +1435,8 @@ For example, `flatten(['a', ['b', ['c']]])` returns ['a','b','c']. #### `floor` +**Deprecated:** This function has been replaced with a built-in [`floor`](https://puppet.com/docs/puppet/latest/function.html#floor) function as of Puppet 6.0.0. + Returns the largest integer less than or equal to the argument. Arguments: A single numeric value. @@ -1363,30 +1506,53 @@ Returns the absolute path of the specified module for the current environment. $module_path = get_module_path('stdlib') ``` +Since Puppet 5.4.0, the built-in [`module_directory`](https://puppet.com/docs/puppet/latest/function.html#module_directory) function does the same thing and will return the path to the first module found, if given multiple values or an array. + *Type*: rvalue. #### `getparam` - Returns the value of a resource's parameter. Arguments: A resource reference and the name of the parameter. -For example, the following returns 'param_value': +> Note: User defined resource types are evaluated lazily. + +*Examples:* ```puppet +# define a resource type with a parameter define example_resource($param) { } +# declare an instance of that type example_resource { "example_resource_instance": - param => "param_value" + param => "'the value we are getting in this example''" } -getparam(Example_resource["example_resource_instance"], "param") +# Because of order of evaluation, a second definition is needed +# that will be evaluated after the first resource has been declared +# +define example_get_param { + # This will notice the value of the parameter + notice(getparam(Example_resource["example_resource_instance"], "param")) +} + +# Declare an instance of the second resource type - this will call notice +example_get_param { 'show_notify': } ``` -*Type*: rvalue. +Would notice: 'the value we are getting in this example' + +Since Puppet 4.0.0, you can get a parameter value by using its data type +and the [ ] operator. The example below is equivalent to a call to getparam(): + +```puppet +Example_resource['example_resource_instance']['param'] +``` #### `getvar` +**Deprecated:** This function has been replaced with a built-in [`getvar`](https://puppet.com/docs/puppet/latest/function.html#getvar) +function as of Puppet 6.0.0. The new version also supports digging into a structured value. Looks up a variable in a remote namespace. @@ -1425,6 +1591,11 @@ Searches through an array and returns any elements that match the provided regul For example, `grep(['aaa','bbb','ccc','aaaddd'], 'aaa')` returns ['aaa','aaaddd']. +Since Puppet 4.0.0, the built-in [`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function +function does the "same" — as any logic can be used to filter, as opposed to just regular expressions: + + ['aaa', 'bbb', 'ccc', 'aaaddd']. filter |$x| { $x =~ 'aaa' } + *Type*: rvalue. #### `has_interface_with` @@ -1468,6 +1639,7 @@ Arguments: A string specifying an IP address. *Type*: rvalue. #### `has_key` +**Deprecated:** This function has been replaced with the built-in operator `in`. Determines if a hash has a certain key value. @@ -1483,13 +1655,26 @@ if has_key($my_hash, 'key_one') { } ``` +Since Puppet 4.0.0, this can be achieved in the Puppet language with the following equivalent expression: + + $my_hash = {'key_one' => 'value_one'} + if 'key_one' in $my_hash { + notice('this will be printed') + } + *Type*: rvalue. #### `hash` +**Deprecated:** This function has been replaced with the built-in ability to create a new value of almost any +data type - see the built-in [`Hash.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-hash-and-struct) function +in Puppet. + Converts an array into a hash. -For example, `hash(['a',1,'b',2,'c',3])` returns {'a'=>1,'b'=>2,'c'=>3}. +For example (deprecated), `hash(['a',1,'b',2,'c',3])` returns {'a'=>1,'b'=>2,'c'=>3}. + +For example (built-in), `Hash(['a',1,'b',2,'c',3])` returns {'a'=>1,'b'=>2,'c'=>3}. *Type*: rvalue. @@ -1657,6 +1842,10 @@ If a value is an array, the key is prefixed to each element. The return value is For example, `join_keys_to_values({'a'=>1,'b'=>[2,3]}, " is ")` results in ["a is 1","b is 2","b is 3"]. +Since Puppet 5.0.0, there is more control over the formatting (including indentations and line breaks, delimiters around arrays and hash entries, between key/values in hash entries, and individual +formatting of values in the array) - see the +built-in [`String.new`](https://docs.puppet.com/puppet/latest/function.html#conversion-to-string) function and its formatting options for `Array` and `Hash`. + *Type*: rvalue. #### `keys` @@ -1739,12 +1928,16 @@ if empty($metadata) { #### `lstrip` +**Deprecated:** This function has been replaced with a built-in [`lstrip`](https://puppet.com/docs/puppet/latest/function.html#lstrip) function as of Puppet 6.0.0. + Strips spaces to the left of a string. *Type*: rvalue. #### `max` +**Deprecated:** This function has been replaced with a built-in [`max`](https://puppet.com/docs/puppet/latest/function.html#max) function as of Puppet 6.0.0. + Returns the highest value of all arguments. Requires at least one argument. Arguments: A numeric or a string representing a number. @@ -1759,6 +1952,18 @@ For example, `member(['a','b'], 'b')` and `member(['a','b','c'], ['b','c'])` ret *Note*: This function does not support nested arrays. If the first argument contains nested arrays, it will not recurse through them. +Since Puppet 4.0.0, you can perform the same in the Puppet language. For single values, +the operator `in` can be used: + + 'a' in ['a', 'b'] # true + +And for arrays, use the operator `-` to compute a diff: + + ['d', 'b'] - ['a', 'b', 'c'] == [] # false because 'd' is not subtracted + ['a', 'b'] - ['a', 'b', 'c'] == [] # true because both 'a' and 'b' are subtracted + +Also note that since Puppet 5.2.0, the general form to test the content of an array or hash is to use the built-in [`any`](https://puppet.com/docs/puppet/latest/function.html#any) and [`all`](https://puppet.com/docs/puppet/latest/function.html#all) functions. + *Type*: rvalue. #### `merge` @@ -1777,10 +1982,16 @@ $merged_hash = merge($hash1, $hash2) When there is a duplicate key, the key in the rightmost hash takes precedence. +Since Puppet 4.0.0, the same merge can be achieved with the + operator. + + $merged_hash = $hash1 + $hash2 + *Type*: rvalue. #### `min` +**Deprecated:** This function has been replaced with a built-in [`min`](https://puppet.com/docs/puppet/latest/function.html#min) function as of Puppet 6.0.0. + Returns the lowest value of all arguments. Requires at least one argument. Arguments: A numeric or a string representing a number. @@ -1789,7 +2000,16 @@ Arguments: A numeric or a string representing a number. #### `num2bool` -Converts a number or a string representation of a number into a true Boolean. Zero or anything non-numeric becomes `false`. Numbers greater than 0 become `true`. +Converts a number, or a string representation of a number, into a true Boolean. +Zero or anything non-numeric becomes `false`. +Numbers greater than 0 become `true`. + +Since Puppet 5.0.0, the same can be achieved with the Puppet Type System. +See the [`Boolean.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-boolean) +function in Puppet for the many available type conversions. + + Boolean(0) # false + Boolean(1) # true *Type*: rvalue. @@ -1838,6 +2058,11 @@ For example: * `prefix(['a','b','c'], 'p')` returns ['pa','pb','pc']. * `prefix({'a'=>'b','b'=>'c','c'=>'d'}, 'p')` returns {'pa'=>'b','pb'=>'c','pc'=>'d'}. +Since Puppet 4.0.0, modify values in array by using the built-in [`map`](https://docs.puppet.com/puppet/latest/function.html#map) function. +This example does the same as the first example above: + + ['a', 'b', 'c'].map |$x| { "p${x}" } + *Type*: rvalue. #### `pry` @@ -1893,6 +2118,12 @@ Passing a third argument causes the generated range to step by that interval. Fo * `range("0", "9", "2")` returns ["0","2","4","6","8"]. +> Note: The Puppet Language supports `Integer` and `Float` ranges by using the type system. They are suitable for iterating a given number of times. + +See the built-in [`step`](https://docs.puppet.com/puppet/latest/function.html#step) function in Puppet for skipping values. + + Integer[0, 9].each |$x| { notice($x) } # notices 0, 1, 2, ... 9 + *Type*: rvalue. #### `regexpescape` @@ -1907,20 +2138,32 @@ Searches through an array and rejects all elements that match the provided regul For example, `reject(['aaa','bbb','ccc','aaaddd'], 'aaa')` returns ['bbb','ccc']. +Since Puppet 4.0.0, the same is true with the built-in [`filter`](https://docs.puppet.com/puppet/latest/function.html#filter) function in Puppet. +The equivalent of the stdlib `reject` function: + + ['aaa','bbb','ccc','aaaddd'].filter |$x| { $x !~ /aaa/ } + *Type*: rvalue. #### `reverse` Reverses the order of a string or array. +> *Note*: The same can be done with the built-in [`reverse_each`](https://docs.puppet.com/puppet/latest/function.html#reverse_each) function in Puppet. + + #### `round` - Rounds a number to the nearest integer +**Deprecated:** This function has been replaced with a built-in [`round`](https://puppet.com/docs/puppet/latest/function.html#round) function as of Puppet 6.0.0. + +Rounds a number to the nearest integer. *Type*: rvalue. #### `rstrip` +**Deprecated:** This function has been replaced with a built-in [`rstrip`](https://puppet.com/docs/puppet/latest/function.html#rstrip) function as of Puppet 6.0.0. + Strips spaces to the right of the string. *Type*: rvalue. @@ -1975,7 +2218,7 @@ Randomizes the order of a string or array elements. #### `size` -**Deprecated:** This function will be replaced with a built-in `size` function as of Puppet 6.0.0. +**Deprecated:** This function has been replaced with a built-in [`size`](https://puppet.com/docs/puppet/latest/function.html#size) function as of Puppet 6.0.0 (`size` is now an alias for `length`). Returns the number of elements in a string, an array or a hash. This function will be deprecated in a future release. For Puppet 4, use the `length` function. @@ -1983,6 +2226,8 @@ Returns the number of elements in a string, an array or a hash. This function wi #### `sprintf_hash` +**Deprecated:** The same functionality can be achieved with the built-in [`sprintf`](https://docs.puppet.com/puppet/latest/function.html#sprintf) function as of Puppet 4.10.10 and 5.3.4. This function will be removed in a future release. + Performs printf-style formatting with named references of text. The first parameter is a format string describing how to format the rest of the parameters in the hash. See Ruby documentation for [`Kernel::sprintf`](https://ruby-doc.org/core-2.4.2/Kernel.html#method-i-sprintf) for details about this function. @@ -1999,11 +2244,13 @@ $output = sprintf_hash('String: %s / number converted to binary: %b #### `sort` +**Deprecated:** This function has been replaced with a built-in [`sort`](https://puppet.com/docs/puppet/latest/function.html#sort) function as of Puppet 6.0.0. + Sorts strings and arrays lexically. *Type*: rvalue. -*Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater. +> *Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater. #### `squeeze` @@ -2015,6 +2262,13 @@ Replaces consecutive repeats (such as 'aaaa') in a string with a single characte Converts certain strings to a Boolean. This attempts to convert strings that contain the values '1', 'true', 't', 'y', or 'yes' to `true`. Strings that contain values '0', 'false', 'f', 'n', or 'no', or that are an empty string or undefined are converted to `false`. Any other value causes an error. These checks are case insensitive. +Since Puppet 5.0.0, the same can be achieved with the Puppet Type System. +See the [`Boolean.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-boolean) +function in Puppet for the many available type conversions. + + Boolean('false'), Boolean('n'), Boolean('no') # all false + Boolean('true'), Boolean('y'), Boolean('yes') # all true + *Type*: rvalue. #### `str2saltedsha512` @@ -2023,10 +2277,12 @@ Converts a string to a salted-SHA512 password hash, used for OS X versions 10.7 *Type*: rvalue. -*Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater. +> *Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater. #### `strftime` +**Deprecated:** This function has been replaced with a built-in [`strftime`](https://puppet.com/docs/puppet/latest/function.html#strftime) function as of Puppet 4.8.0. + Returns formatted time. For example, `strftime("%s")` returns the time since Unix epoch, and `strftime("%Y-%m-%d")` returns the date. @@ -2035,7 +2291,7 @@ Arguments: A string specifying the time in `strftime` format. See the Ruby [strf *Type*: rvalue. -*Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater. +> *Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater. *Format:* @@ -2087,6 +2343,8 @@ Arguments: A string specifying the time in `strftime` format. See the Ruby [strf #### `strip` +**Deprecated:** This function has been replaced with a built-in [`strip`](https://puppet.com/docs/puppet/latest/function.html#strip) function as of Puppet 6.0.0. + Removes leading and trailing whitespace from a string or from every string inside an array. For example, `strip(" aaa ")` results in "aaa". *Type*: rvalue. @@ -2100,6 +2358,10 @@ For example: * `suffix(['a','b','c'], 'p')` returns ['ap','bp','cp']. * `suffix({'a'=>'b','b'=>'c','c'=>'d'}, 'p')` returns {'ap'=>'b','bp'=>'c','cp'=>'d'}. +Note that since Puppet 4.0.0 the general way to modify values is in array is by using the built-in [`map`](https://docs.puppet.com/puppet/latest/function.html#map) function. These example does the same as the first example above: + + ['a', 'b', 'c'].map |$x| { "${x}p" } + *Type*: rvalue. #### `swapcase` @@ -2108,7 +2370,7 @@ Swaps the existing case of a string. For example, `swapcase("aBcD")` results in *Type*: rvalue. -*Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater. +> *Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater. #### `time` @@ -2116,6 +2378,10 @@ Returns the current Unix epoch time as an integer. For example, `time()` returns something like '1311972653'. +Since Puppet 4.8.0, the Puppet language has the data types `Timestamp` (a point in time) and `Timespan` (a duration). The following example is equivalent to calling `time()` without any arguments: + + Timestamp() + *Type*: rvalue. #### `to_bytes` @@ -2259,6 +2525,8 @@ See also [dos2unix](#dos2unix). #### `upcase` +**Deprecated:** This function has been replaced with a built-in [`upcase`](https://puppet.com/docs/puppet/latest/function.html#upcase) function as of Puppet 6.0.0. + Converts an object, array, or hash of objects to uppercase. Objects to be converted must respond to upcase. For example, `upcase('abcd')` returns 'ABCD'. @@ -2275,7 +2543,7 @@ Arguments: Either a single string or an array of strings. *Type*: rvalue. -*Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater. +> *Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater. #### `validate_absolute_path` @@ -2764,7 +3032,7 @@ validate_string(true) validate_string([ 'some', 'array' ]) ``` -*Note:* validate_string(`undef`) will not fail in this version of the functions API. +> *Note:* validate_string(`undef`) will not fail in this version of the functions API. Instead, use: @@ -2822,6 +3090,15 @@ For example: * `values_at(['a','b','c'], ["0-1"])` returns ['a','b']. * `values_at(['a','b','c','d','e'], [0, "2-3"])` returns ['a','c','d']. +Since Puppet 4.0.0, you can slice an array with index and count directly in the language. +A negative value is taken to be "from the end" of the array, for example: + +```puppet +['a', 'b', 'c', 'd'][1, 2] # results in ['b', 'c'] +['a', 'b', 'c', 'd'][2, -1] # results in ['c', 'd'] +['a', 'b', 'c', 'd'][1, -2] # results in ['b', 'c'] +``` + *Type*: rvalue. #### `zip` diff --git a/lib/puppet/functions/length.rb b/lib/puppet/functions/length.rb index 8cd43e5f4..ccd662a16 100644 --- a/lib/puppet/functions/length.rb +++ b/lib/puppet/functions/length.rb @@ -1,4 +1,9 @@ -# A function to eventually replace the old size() function for stdlib - The original size function did not handle Puppets new type capabilities, so this function is a Puppet 4 compatible solution. +# A function to eventually replace the old size() function for stdlib +# The original size function did not handle Puppets new type capabilities, so this function is a Puppet 4 compatible solution. +# +# Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core +# will be used instead of this function. +# Puppet::Functions.create_function(:length) do dispatch :length do param 'Variant[String,Array,Hash]', :value diff --git a/lib/puppet/functions/sprintf_hash.rb b/lib/puppet/functions/sprintf_hash.rb index 2536bc9dd..47fcd413f 100644 --- a/lib/puppet/functions/sprintf_hash.rb +++ b/lib/puppet/functions/sprintf_hash.rb @@ -12,6 +12,9 @@ # { 'foo' => 'a string', 'number' => 5 }) # # $output = 'String: a string / number converted to binary: 101' # +# Note that since Puppet 4.10.10, and 5.3.4 this functionality is supported by the +# `sprintf` function in puppet core. +# Puppet::Functions.create_function(:sprintf_hash) do # @param format The format to use. # @param arguments Hash with parameters. diff --git a/lib/puppet/parser/functions/abs.rb b/lib/puppet/parser/functions/abs.rb index 84bef8c2e..59e468e98 100644 --- a/lib/puppet/parser/functions/abs.rb +++ b/lib/puppet/parser/functions/abs.rb @@ -5,6 +5,9 @@ module Puppet::Parser::Functions newfunction(:abs, :type => :rvalue, :doc => <<-DOC Returns the absolute value of a number, for example -34.56 becomes 34.56. Takes a single integer and float value as an argument. + + Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core + will be used instead of this function. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/any2array.rb b/lib/puppet/parser/functions/any2array.rb index 510c2d5bc..cd4e4c8db 100644 --- a/lib/puppet/parser/functions/any2array.rb +++ b/lib/puppet/parser/functions/any2array.rb @@ -6,6 +6,23 @@ module Puppet::Parser::Functions This converts any object to an array containing that object. Empty argument lists are converted to an empty array. Arrays are left untouched. Hashes are converted to arrays of alternating keys and values. + + Note that since Puppet 5.0.0 it is possible to create new data types for almost any + datatype using the type system and the built-in + [`Array.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-array-and-tuple) + function is used to create a new Array.. + + $hsh = {'key' => 42, 'another-key' => 100} + notice(Array($hsh)) + + Would notice `[['key', 42], ['another-key', 100]]` + + The Array data type also has a special mode to "create an array if not already an array" + + notice(Array({'key' => 42, 'another-key' => 100}, true)) + + Would notice `[{'key' => 42, 'another-key' => 100}]`, as the `true` flag prevents the hash from being + transformed into an array. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/any2bool.rb b/lib/puppet/parser/functions/any2bool.rb index 9eb634d7f..8f6d5d81a 100644 --- a/lib/puppet/parser/functions/any2bool.rb +++ b/lib/puppet/parser/functions/any2bool.rb @@ -11,6 +11,9 @@ module Puppet::Parser::Functions * Number (or a string representation of a number) > 0 will return true, otherwise false * undef will return false * Anything else will return true + + Also see the built-in [`Boolean.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-boolean) + function. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/base64.rb b/lib/puppet/parser/functions/base64.rb index 35114e7d4..d77db8bbf 100644 --- a/lib/puppet/parser/functions/base64.rb +++ b/lib/puppet/parser/functions/base64.rb @@ -13,6 +13,15 @@ module Puppet::Parser::Functions $encodestring = base64('encode', 'thestring', $method) $decodestring = base64('decode', 'dGhlc3RyaW5n', $method) + Note: Since Puppet 4.8.0, the Binary data type can be used to produce base 64 encoded strings. + See the `new()` function for the Binary and String types for documentation. Also see `binary_file()` + function for reading a file with binary (non UTF-8) content. + + # encode a string as if it was binary + $encodestring = String(Binary('thestring', '%s')) + # decode a Binary assuming it is an UTF-8 String + $decodestring = String(Binary("dGhlc3RyaW5n"), "%s") + DOC require 'base64' diff --git a/lib/puppet/parser/functions/bool2num.rb b/lib/puppet/parser/functions/bool2num.rb index e8ad96166..115467e76 100644 --- a/lib/puppet/parser/functions/bool2num.rb +++ b/lib/puppet/parser/functions/bool2num.rb @@ -7,6 +7,16 @@ module Puppet::Parser::Functions false, f, 0, n, and no to 0 true, t, 1, y, and yes to 1 Requires a single boolean or string as an input. + + Note that since Puppet 5.0.0 it is possible to create new data types for almost any + datatype using the type system and the built-in + [`Numeric.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-numeric), + [`Integer.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-integer), and + [`Float.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-float) + function are used to convert to numeric values. + + notice(Integer(false)) # Notices 0 + notice(Float(true)) # Notices 1.0 DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/bool2str.rb b/lib/puppet/parser/functions/bool2str.rb index 502ab2e0c..be25e0a18 100644 --- a/lib/puppet/parser/functions/bool2str.rb +++ b/lib/puppet/parser/functions/bool2str.rb @@ -15,6 +15,17 @@ module Puppet::Parser::Functions bool2str(false, 't', 'f') => 'f' Requires a single boolean as an input. + + Note that since Puppet 5.0.0 it is possible to create new data types for almost any + datatype using the type system and the built-in + [`String.new`](https://puppet.com/docs/puppet/latest/function.html#boolean-to-string) + function is used to convert to String with many different format options. + + notice(String(false)) # Notices 'false' + notice(String(true)) # Notices 'true' + notice(String(false, '%y')) # Notices 'yes' + notice(String(true, '%y')) # Notices 'no' + DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/camelcase.rb b/lib/puppet/parser/functions/camelcase.rb index fdc54a23c..3c887e26b 100644 --- a/lib/puppet/parser/functions/camelcase.rb +++ b/lib/puppet/parser/functions/camelcase.rb @@ -5,6 +5,9 @@ module Puppet::Parser::Functions newfunction(:camelcase, :type => :rvalue, :doc => <<-DOC Converts the case of a string or all strings in an array to camel case. + + Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core + will be used instead of this function. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/capitalize.rb b/lib/puppet/parser/functions/capitalize.rb index 7d7703fe3..2493bc838 100644 --- a/lib/puppet/parser/functions/capitalize.rb +++ b/lib/puppet/parser/functions/capitalize.rb @@ -6,6 +6,9 @@ module Puppet::Parser::Functions newfunction(:capitalize, :type => :rvalue, :doc => <<-DOC Capitalizes the first letter of a string or array of strings. Requires either a single string or an array as an input. + + Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core + will be used instead of this function. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/ceiling.rb b/lib/puppet/parser/functions/ceiling.rb index d0323a884..fe4b76836 100644 --- a/lib/puppet/parser/functions/ceiling.rb +++ b/lib/puppet/parser/functions/ceiling.rb @@ -5,6 +5,9 @@ module Puppet::Parser::Functions newfunction(:ceiling, :type => :rvalue, :doc => <<-DOC Returns the smallest integer greater or equal to the argument. Takes a single numeric value as an argument. + + Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core + will be used instead of this function. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/chomp.rb b/lib/puppet/parser/functions/chomp.rb index 0e9cd6dc4..b7b309c07 100644 --- a/lib/puppet/parser/functions/chomp.rb +++ b/lib/puppet/parser/functions/chomp.rb @@ -6,6 +6,9 @@ module Puppet::Parser::Functions 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. + + Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core + will be used instead of this function. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/chop.rb b/lib/puppet/parser/functions/chop.rb index 80e896481..39a9ee774 100644 --- a/lib/puppet/parser/functions/chop.rb +++ b/lib/puppet/parser/functions/chop.rb @@ -8,6 +8,9 @@ module Puppet::Parser::Functions string returns an empty string. If you wish to merely remove record separators then you should use the `chomp` function. Requires a string or array of strings as input. + + Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core + will be used instead of this function. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/clamp.rb b/lib/puppet/parser/functions/clamp.rb index 0aea5112f..cbc67dc95 100644 --- a/lib/puppet/parser/functions/clamp.rb +++ b/lib/puppet/parser/functions/clamp.rb @@ -4,6 +4,9 @@ module Puppet::Parser::Functions newfunction(:clamp, :type => :rvalue, :arity => -2, :doc => <<-DOC Clamps value to a range. + + Note: From Puppet 6.0.0 this can be done with only core Puppet like this: + [$minval, $maxval, $value_to_clamp].sort[1] DOC ) do |args| diff --git a/lib/puppet/parser/functions/concat.rb b/lib/puppet/parser/functions/concat.rb index 9a83ec118..136f402a4 100644 --- a/lib/puppet/parser/functions/concat.rb +++ b/lib/puppet/parser/functions/concat.rb @@ -12,6 +12,10 @@ module Puppet::Parser::Functions Would result in: ['1','2','3','4','5','6','7','8','9'] + + Note: Since Puppet 4.0 concatenation of arrays and hashes can be done with the + operator. + + ['1','2','3'] + ['4','5','6'] + ['7','8','9'] DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/convert_base.rb b/lib/puppet/parser/functions/convert_base.rb index 6d17f85b6..da5ff2690 100644 --- a/lib/puppet/parser/functions/convert_base.rb +++ b/lib/puppet/parser/functions/convert_base.rb @@ -10,6 +10,11 @@ module Puppet::Parser::Functions $binary_repr = convert_base(5, 2) # $binary_repr is now set to "101" $hex_repr = convert_base("254", "16") # $hex_repr is now set to "fe" + Note: Since Puppet 4.5.0 this can be done with String.new() and its many formatting options: + + $binary_repr = String(5, '%b') # results in "101" + $hex_repr = String(254, "%x") # results in "fe" + $hex_repr = String(254, "%#x") # results in "0xfe" DOC raise Puppet::ParseError, 'convert_base(): First argument must be either a string or an integer' unless args[0].is_a?(Integer) || args[0].is_a?(String) diff --git a/lib/puppet/parser/functions/count.rb b/lib/puppet/parser/functions/count.rb index f5ac8c3bd..8bc5469af 100644 --- a/lib/puppet/parser/functions/count.rb +++ b/lib/puppet/parser/functions/count.rb @@ -4,8 +4,20 @@ module Puppet::Parser::Functions newfunction(:count, :type => :rvalue, :arity => -2, :doc => <<-DOC 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. + Count the number of elements in array that is equal to the second argument. + If called with only an array it counts the number of elements that are not nil/undef/empty-string. + + Note: equality is tested with a Ruby method and it is therefore subject to what Ruby considers + to be equal. For strings this means that equality is case sensitive. + + In Puppet core, counting can be done in general by using a combination of the core functions + filter() (since Puppet 4.0.0) and length() (since Puppet 5.5.0, before that in stdlib). + Example below shows counting values that are not undef. + + notice([42, "hello", undef].filter |$x| { $x =~ NotUndef }.length) + + Would notice the value 2. + DOC ) do |args| diff --git a/lib/puppet/parser/functions/delete.rb b/lib/puppet/parser/functions/delete.rb index f83ff16e9..d3fddd85b 100644 --- a/lib/puppet/parser/functions/delete.rb +++ b/lib/puppet/parser/functions/delete.rb @@ -19,6 +19,22 @@ module Puppet::Parser::Functions delete('abracadabra', 'bra') Would return: 'acada' + + Note that from Puppet 4.0.0 the minus (-) operator deletes values from arrays and keys from a hash: + + ['a', 'b', 'c', 'b'] - 'b' + # would return ['a', 'c'] + + {'a'=>1,'b'=>2,'c'=>3} - ['b','c']) + # would return {'a' => '1'} + + A global delete from a string can be performed with the regsubst() function: + + 'abracadabra'.regsubst(/bra/, '', 'G') + # would return 'acada' + + In general, the filter() function can filter out entries from arrays and hashes based on keys and/or values. + DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/delete_at.rb b/lib/puppet/parser/functions/delete_at.rb index e40ad2648..0a1a9400b 100644 --- a/lib/puppet/parser/functions/delete_at.rb +++ b/lib/puppet/parser/functions/delete_at.rb @@ -10,6 +10,17 @@ module Puppet::Parser::Functions delete_at(['a','b','c'], 1) Would return: ['a','c'] + + Note that since Puppet 4 this can be done in general with the filter function: + + ['a', 'b', 'c'].filter |$pos, $val | { $pos != 1 } + + Or if a delete is wanted from the beginning or end of the array, by using the slice operator [ ]: + + $array[0, -1] # the same as all the values + $array[2, -1] # all but the first 2 elements + $array[0, -3] # all but the last 2 elements + $array[1, -2] # all but the first and last element DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/delete_regex.rb b/lib/puppet/parser/functions/delete_regex.rb index 64cad9c9f..8093896f4 100644 --- a/lib/puppet/parser/functions/delete_regex.rb +++ b/lib/puppet/parser/functions/delete_regex.rb @@ -22,6 +22,12 @@ module Puppet::Parser::Functions delete_regex({'a'=>1,'b'=>2,'c'=>3}, '^a$') Would return: {'b'=>2,'c'=>3} + Note that since Puppet 4 this can be done in general with the filter function: + + ["aaa", "aba", "aca"].filter |$val| { $val !~ /b/ } + # Would return: ['aaa', 'aca'] + + DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/delete_undef_values.rb b/lib/puppet/parser/functions/delete_undef_values.rb index af2dbc783..b41b5f236 100644 --- a/lib/puppet/parser/functions/delete_undef_values.rb +++ b/lib/puppet/parser/functions/delete_undef_values.rb @@ -15,6 +15,11 @@ module Puppet::Parser::Functions Would return: ['A','',false] + Note that since Puppet 4.0.0 the equivalent can be performed with the filter() function in Puppet: + + $array.filter |$val| { $val =~ NotUndef } + $hash.filter |$key, $val| { $val =~ NotUndef } + DOC ) do |args| diff --git a/lib/puppet/parser/functions/delete_values.rb b/lib/puppet/parser/functions/delete_values.rb index 1192766de..f98f247f9 100644 --- a/lib/puppet/parser/functions/delete_values.rb +++ b/lib/puppet/parser/functions/delete_values.rb @@ -11,6 +11,11 @@ module Puppet::Parser::Functions Would return: {'a'=>'A','c'=>'C','B'=>'D'} + Note that since Puppet 4.0.0 the equivalent can be performed with the filter() function in Puppet: + + $array.filter |$val| { $val != 'B' } + $hash.filter |$key, $val| { $val != 'B' } + DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/difference.rb b/lib/puppet/parser/functions/difference.rb index cfaebc9d4..360c1e307 100644 --- a/lib/puppet/parser/functions/difference.rb +++ b/lib/puppet/parser/functions/difference.rb @@ -12,6 +12,12 @@ module Puppet::Parser::Functions difference(["a","b","c"],["b","c","d"]) Would return: ["a"] + + Note: Since Puppet 4 the minus (-) operator in the Puppet language does the same thing: + + ['a', 'b', 'c'] - ['b', 'c', 'd'] + # would return ['a'] + DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/dig44.rb b/lib/puppet/parser/functions/dig44.rb index e7e78bfa2..91724f43c 100644 --- a/lib/puppet/parser/functions/dig44.rb +++ b/lib/puppet/parser/functions/dig44.rb @@ -7,7 +7,7 @@ module Puppet::Parser::Functions :type => :rvalue, :arity => -2, :doc => <<-DOC - DEPRECATED: This function has been replaced in puppet 4.5.0. + DEPRECATED: This function has been replaced in Puppet 4.5.0. Looks up into a complex structure of arrays and hashes and returns a value or the default value if nothing was found. diff --git a/lib/puppet/parser/functions/downcase.rb b/lib/puppet/parser/functions/downcase.rb index 1661e562c..0c763752e 100644 --- a/lib/puppet/parser/functions/downcase.rb +++ b/lib/puppet/parser/functions/downcase.rb @@ -5,6 +5,9 @@ module Puppet::Parser::Functions newfunction(:downcase, :type => :rvalue, :doc => <<-DOC Converts the case of a string or all strings in an array to lower case. + + Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core + will be used instead of this function. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/empty.rb b/lib/puppet/parser/functions/empty.rb index 79c43d0b1..e0b9838e2 100644 --- a/lib/puppet/parser/functions/empty.rb +++ b/lib/puppet/parser/functions/empty.rb @@ -4,6 +4,9 @@ module Puppet::Parser::Functions newfunction(:empty, :type => :rvalue, :doc => <<-DOC Returns true if the variable is empty. + + Note: from Puppet 5.5.0, the compatible function with the same name in Puppet core + will be used instead of this function. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/flatten.rb b/lib/puppet/parser/functions/flatten.rb index 15970dfa5..6be5962b2 100644 --- a/lib/puppet/parser/functions/flatten.rb +++ b/lib/puppet/parser/functions/flatten.rb @@ -11,6 +11,9 @@ module Puppet::Parser::Functions flatten(['a', ['b', ['c']]]) Would return: ['a','b','c'] + + Note: from Puppet 5.5.0, the compatible function with the same name in Puppet core + will be used instead of this function. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/floor.rb b/lib/puppet/parser/functions/floor.rb index 9fcb048aa..df132fc38 100644 --- a/lib/puppet/parser/functions/floor.rb +++ b/lib/puppet/parser/functions/floor.rb @@ -5,6 +5,9 @@ module Puppet::Parser::Functions newfunction(:floor, :type => :rvalue, :doc => <<-DOC Returns the largest integer less or equal to the argument. Takes a single numeric value as an argument. + + Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core + will be used instead of this function. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/get_module_path.rb b/lib/puppet/parser/functions/get_module_path.rb index 3a95b711e..3ec6ccd3c 100644 --- a/lib/puppet/parser/functions/get_module_path.rb +++ b/lib/puppet/parser/functions/get_module_path.rb @@ -8,6 +8,9 @@ module Puppet::Parser::Functions Example: $module_path = get_module_path('stdlib') + + Note that since Puppet 5.4.0 the function `module_directory()` in Puppet does the same thing and will return + the path to the first found module if given multiple values or an array. DOC ) do |args| raise(Puppet::ParseError, 'get_module_path(): Wrong number of arguments, expects one') unless args.size == 1 diff --git a/lib/puppet/parser/functions/getparam.rb b/lib/puppet/parser/functions/getparam.rb index d73650bd1..95981b360 100644 --- a/lib/puppet/parser/functions/getparam.rb +++ b/lib/puppet/parser/functions/getparam.rb @@ -5,20 +5,38 @@ :type => :rvalue, :doc => <<-'DOC' Takes a resource reference and name of the parameter and - returns value of resource's parameter. + returns value of resource's parameter. Note that user defined + resource types are evaluated lazily. *Examples:* + # define a resource type with a parameter define example_resource($param) { } + # declare an instance of that type example_resource { "example_resource_instance": - param => "param_value" + param => "'the value we are getting in this example''" } - getparam(Example_resource["example_resource_instance"], "param") + # Because of order of evaluation, a second definition is needed + # that will be evaluated after the first resource has been declared + # + define example_get_param { + # This will notice the value of the parameter + notice(getparam(Example_resource["example_resource_instance"], "param")) + } + + # Declare an instance of the second resource type - this will call notice + example_get_param { 'show_notify': } + + Would notice: 'the value we are getting in this example' + + Note that since Puppet 4.0.0 it is possible to get a parameter value by using its data type + and the [ ] operator. The example below is equivalent to a call to getparam(): + + Example_resource['example_resource_instance']['param'] - Would return: param_value DOC ) do |vals| reference, param = vals diff --git a/lib/puppet/parser/functions/getvar.rb b/lib/puppet/parser/functions/getvar.rb index f4644677e..fddbd82f0 100644 --- a/lib/puppet/parser/functions/getvar.rb +++ b/lib/puppet/parser/functions/getvar.rb @@ -3,7 +3,8 @@ # module Puppet::Parser::Functions newfunction(:getvar, :type => :rvalue, :doc => <<-'DOC') do |args| - Lookup a variable in a remote namespace. + Lookup a variable in a given namespace. + Returns undef if variable does not exist. For example: @@ -15,6 +16,11 @@ module Puppet::Parser::Functions $datalocation = 'site::data' $bar = getvar("${datalocation}::bar") # Equivalent to $bar = $site::data::bar + + Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core + will be used instead of this function. The new function also has support for + digging into a structured value. See the built-in + [`getvar`](https://puppet.com/docs/puppet/latest/function.html#getvar) function DOC unless args.length == 1 @@ -27,7 +33,7 @@ module Puppet::Parser::Functions result = lookupvar((args[0]).to_s) end - # avoid relying on incosistent behaviour around ruby return values from catch + # avoid relying on inconsistent behaviour around ruby return values from catch result rescue Puppet::ParseError # rubocop:disable Lint/HandleExceptions : Eat the exception if strict_variables = true is set end diff --git a/lib/puppet/parser/functions/grep.rb b/lib/puppet/parser/functions/grep.rb index 030c14ae1..b6881bf36 100644 --- a/lib/puppet/parser/functions/grep.rb +++ b/lib/puppet/parser/functions/grep.rb @@ -13,6 +13,10 @@ module Puppet::Parser::Functions Would return: ['aaa','aaaddd'] + + Note that since Puppet 4.0.0, the filter() function in Puppet can do the same: + + ['aaa', 'bbb', 'ccc', 'aaaddd']. filter |$x| { $x =~ 'aaa' } DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/has_key.rb b/lib/puppet/parser/functions/has_key.rb index 53b8c74e9..8bf74f049 100644 --- a/lib/puppet/parser/functions/has_key.rb +++ b/lib/puppet/parser/functions/has_key.rb @@ -15,6 +15,12 @@ module Puppet::Parser::Functions notice('this will be printed') } + Note: Since Puppet 4.0.0 this can be achieved in the Puppet language with the following equivalent expression: + + $my_hash = {'key_one' => 'value_one'} + if 'key_one' in $my_hash { + notice('this will be printed') + } DOC unless args.length == 2 diff --git a/lib/puppet/parser/functions/hash.rb b/lib/puppet/parser/functions/hash.rb index f6644dbb1..0162e8327 100644 --- a/lib/puppet/parser/functions/hash.rb +++ b/lib/puppet/parser/functions/hash.rb @@ -10,6 +10,13 @@ module Puppet::Parser::Functions hash(['a',1,'b',2,'c',3]) Would return: {'a'=>1,'b'=>2,'c'=>3} + + Note: Since Puppet 5.0.0 type conversions can in general be performed by using the Puppet Type System. + See the function new() in Puppet for a wide range of available type conversions. + This example shows the equivalent expression in the Puppet language: + + Hash(['a',1,'b',2,'c',3]) + Hash([['a',1],['b',2],['c',3]]) DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/join.rb b/lib/puppet/parser/functions/join.rb index bcb97b70c..d2d7019f2 100644 --- a/lib/puppet/parser/functions/join.rb +++ b/lib/puppet/parser/functions/join.rb @@ -10,6 +10,9 @@ module Puppet::Parser::Functions join(['a','b','c'], ",") Would result in: "a,b,c" + + Note: from Puppet 5.4.0, the compatible function with the same name in Puppet core + will be used instead of this function. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/join_keys_to_values.rb b/lib/puppet/parser/functions/join_keys_to_values.rb index 3232fa87a..99876d023 100644 --- a/lib/puppet/parser/functions/join_keys_to_values.rb +++ b/lib/puppet/parser/functions/join_keys_to_values.rb @@ -1,5 +1,5 @@ # -# join.rb +# join_keys_to_values.rb # module Puppet::Parser::Functions newfunction(:join_keys_to_values, :type => :rvalue, :doc => <<-DOC @@ -17,6 +17,11 @@ module Puppet::Parser::Functions join_keys_to_values({'a'=>1,'b'=>[2,3]}, " is ") Would result in: ["a is 1","b is 2","b is 3"] + + Note: Since Puppet 5.0.0 - for more detailed control over the formatting (including indentations and + line breaks, delimiters around arrays and hash entries, between key/values in hash entries, and individual + formatting of values in the array) - see the `new` function for `String` and its formatting + options for `Array` and `Hash`. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/keys.rb b/lib/puppet/parser/functions/keys.rb index 0ecd48f9e..f3663b7b0 100644 --- a/lib/puppet/parser/functions/keys.rb +++ b/lib/puppet/parser/functions/keys.rb @@ -4,6 +4,9 @@ module Puppet::Parser::Functions newfunction(:keys, :type => :rvalue, :doc => <<-DOC Returns the keys of a hash as an array. + + Note: from Puppet 5.5.0, the compatible function with the same name in Puppet core + will be used instead of this function. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/lstrip.rb b/lib/puppet/parser/functions/lstrip.rb index f5b9a5867..99874e468 100644 --- a/lib/puppet/parser/functions/lstrip.rb +++ b/lib/puppet/parser/functions/lstrip.rb @@ -4,6 +4,9 @@ module Puppet::Parser::Functions newfunction(:lstrip, :type => :rvalue, :doc => <<-DOC Strips leading spaces to the left of a string. + + Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core + will be used instead of this function. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/max.rb b/lib/puppet/parser/functions/max.rb index 21c5245b3..4715dcd4e 100644 --- a/lib/puppet/parser/functions/max.rb +++ b/lib/puppet/parser/functions/max.rb @@ -5,6 +5,9 @@ module Puppet::Parser::Functions newfunction(:max, :type => :rvalue, :doc => <<-DOC Returns the highest value of all arguments. Requires at least one argument. + + Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core + will be used instead of this function. DOC ) do |args| diff --git a/lib/puppet/parser/functions/member.rb b/lib/puppet/parser/functions/member.rb index 9261080bb..8154f3b03 100644 --- a/lib/puppet/parser/functions/member.rb +++ b/lib/puppet/parser/functions/member.rb @@ -25,6 +25,19 @@ module Puppet::Parser::Functions member(['a', 'b', 'c'], ['d', 'b']) would return: false + + Note: Since Puppet 4.0.0 the same can be performed in the Puppet language. For single values + the operator `in` can be used: + + 'a' in ['a', 'b'] # true + + And for arrays by using operator `-` to compute a diff: + + ['d', 'b'] - ['a', 'b', 'c'] == [] # false because 'd' is not subtracted + ['a', 'b'] - ['a', 'b', 'c'] == [] # true because both 'a' and 'b' are subtracted + + Also note that since Puppet 5.2.0 the general form of testing content of an array or hash is to use the built-in + `any` and `all` functions. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/merge.rb b/lib/puppet/parser/functions/merge.rb index 25ebc79ff..1ca825751 100644 --- a/lib/puppet/parser/functions/merge.rb +++ b/lib/puppet/parser/functions/merge.rb @@ -15,6 +15,9 @@ module Puppet::Parser::Functions When there is a duplicate key, the key in the rightmost hash will "win." + Note that since Puppet 4.0.0 the same merge can be achieved with the + operator. + + $merged_hash = $hash1 + $hash2 DOC if args.length < 2 diff --git a/lib/puppet/parser/functions/min.rb b/lib/puppet/parser/functions/min.rb index 985ec562f..ed4be5b20 100644 --- a/lib/puppet/parser/functions/min.rb +++ b/lib/puppet/parser/functions/min.rb @@ -5,6 +5,9 @@ module Puppet::Parser::Functions newfunction(:min, :type => :rvalue, :doc => <<-DOC Returns the lowest value of all arguments. Requires at least one argument. + + Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core + will be used instead of this function. DOC ) do |args| diff --git a/lib/puppet/parser/functions/num2bool.rb b/lib/puppet/parser/functions/num2bool.rb index 0957c56e3..5e0f49424 100644 --- a/lib/puppet/parser/functions/num2bool.rb +++ b/lib/puppet/parser/functions/num2bool.rb @@ -6,6 +6,12 @@ module Puppet::Parser::Functions This function converts a number or a string representation of a number into a true boolean. Zero or anything non-numeric becomes false. Numbers higher then 0 become true. + + Note that since Puppet 5.0.0 the same can be achieved with the Puppet Type System. + See the new() function in Puppet for the many available type conversions. + + Boolean(0) # false + Boolean(1) # true DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/prefix.rb b/lib/puppet/parser/functions/prefix.rb index 7490a1845..f1e1234b3 100644 --- a/lib/puppet/parser/functions/prefix.rb +++ b/lib/puppet/parser/functions/prefix.rb @@ -10,6 +10,11 @@ module Puppet::Parser::Functions prefix(['a','b','c'], 'p') Will return: ['pa','pb','pc'] + + Note that since Puppet 4.0.0 the general way to modify values is in array is by using the map + function in Puppet. This example does the same as the example above: + + ['a', 'b', 'c'].map |$x| { "p${x}" } DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/range.rb b/lib/puppet/parser/functions/range.rb index 3e5cc4406..31baee51c 100644 --- a/lib/puppet/parser/functions/range.rb +++ b/lib/puppet/parser/functions/range.rb @@ -32,6 +32,11 @@ module Puppet::Parser::Functions range("0", "9", "2") Will return: [0,2,4,6,8] + + The Puppet Language support Integer and Float ranges by using the type system. Those are suitable for + iterating a given number of times. Also see the step() function in Puppet for skipping values. + + Integer[0, 9].each |$x| { notice($x) } # notices 0, 1, 2, ... 9 DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/reject.rb b/lib/puppet/parser/functions/reject.rb index be2f01769..392f62eb9 100644 --- a/lib/puppet/parser/functions/reject.rb +++ b/lib/puppet/parser/functions/reject.rb @@ -13,6 +13,11 @@ module Puppet::Parser::Functions Would return: ['bbb','ccc'] + + Note that since Puppet 4.0.0 the same is in general done with the filter function. Here is the + equivalence of the reject() function: + + ['aaa','bbb','ccc','aaaddd'].filter |$x| { $x !~ /aaa/ } DOC if args.size != 2 diff --git a/lib/puppet/parser/functions/reverse.rb b/lib/puppet/parser/functions/reverse.rb index ea911ec3d..9f7db8b2f 100644 --- a/lib/puppet/parser/functions/reverse.rb +++ b/lib/puppet/parser/functions/reverse.rb @@ -4,6 +4,8 @@ module Puppet::Parser::Functions newfunction(:reverse, :type => :rvalue, :doc => <<-DOC Reverses the order of a string or array. + + Note that the same can be done with the reverse_each() function in Puppet. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/round.rb b/lib/puppet/parser/functions/round.rb index b4f2c2b15..aaef51a25 100644 --- a/lib/puppet/parser/functions/round.rb +++ b/lib/puppet/parser/functions/round.rb @@ -15,6 +15,8 @@ module Puppet::Parser::Functions returns: 2 + Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core + will be used instead of this function. DOC ) do |args| diff --git a/lib/puppet/parser/functions/rstrip.rb b/lib/puppet/parser/functions/rstrip.rb index 3e04b27ff..e2cee40bd 100644 --- a/lib/puppet/parser/functions/rstrip.rb +++ b/lib/puppet/parser/functions/rstrip.rb @@ -4,6 +4,9 @@ module Puppet::Parser::Functions newfunction(:rstrip, :type => :rvalue, :doc => <<-DOC Strips leading spaces to the right of the string. + + Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core + will be used instead of this function. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/size.rb b/lib/puppet/parser/functions/size.rb index 27f9614ab..2002a3df5 100644 --- a/lib/puppet/parser/functions/size.rb +++ b/lib/puppet/parser/functions/size.rb @@ -4,6 +4,9 @@ module Puppet::Parser::Functions newfunction(:size, :type => :rvalue, :doc => <<-DOC Returns the number of elements in a string, an array or a hash + + Note that since Puppet 5.4.0, the length() function in Puppet is preferred over this. For versions + of Puppet < 5.4.0 use the stdlib length() function. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/sort.rb b/lib/puppet/parser/functions/sort.rb index f0b4a144f..65308da5e 100644 --- a/lib/puppet/parser/functions/sort.rb +++ b/lib/puppet/parser/functions/sort.rb @@ -5,6 +5,8 @@ module Puppet::Parser::Functions newfunction(:sort, :type => :rvalue, :doc => <<-DOC Sorts strings and arrays lexically. + + Note that from Puppet 6.0.0 the same function in Puppet will be used instead of this. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/str2bool.rb b/lib/puppet/parser/functions/str2bool.rb index 95c260ccb..5f8b8fecd 100644 --- a/lib/puppet/parser/functions/str2bool.rb +++ b/lib/puppet/parser/functions/str2bool.rb @@ -6,6 +6,9 @@ module Puppet::Parser::Functions This converts a string to a boolean. This attempt to convert strings that contain things like: Y,y, 1, T,t, TRUE,true to 'true' and strings that contain things like: 0, F,f, N,n, false, FALSE, no to 'false'. + + Note that since Puppet 5.0.0 the Boolean data type can convert strings to a Boolean value. + See the function new() in Puppet for details what the Boolean data type supports. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/strftime.rb b/lib/puppet/parser/functions/strftime.rb index 53cf7490f..045d25681 100644 --- a/lib/puppet/parser/functions/strftime.rb +++ b/lib/puppet/parser/functions/strftime.rb @@ -6,6 +6,9 @@ module Puppet::Parser::Functions newfunction(:strftime, :type => :rvalue, :doc => <<-DOC This function returns formatted time. + Note that since Puppet 4.8.0 the function with the same name in Puppet will be used instead of this + function. It also supports the Timestamp and Timespan data types in the Puppet language. + *Examples:* To return the time since epoch: diff --git a/lib/puppet/parser/functions/strip.rb b/lib/puppet/parser/functions/strip.rb index 6a147cd20..59d15a33a 100644 --- a/lib/puppet/parser/functions/strip.rb +++ b/lib/puppet/parser/functions/strip.rb @@ -11,6 +11,9 @@ module Puppet::Parser::Functions strip(" aaa ") Would result in: "aaa" + + Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core + will be used instead of this function. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/suffix.rb b/lib/puppet/parser/functions/suffix.rb index 407cd53a6..72ff08dd7 100644 --- a/lib/puppet/parser/functions/suffix.rb +++ b/lib/puppet/parser/functions/suffix.rb @@ -11,6 +11,12 @@ module Puppet::Parser::Functions suffix(['a','b','c'], 'p') Will return: ['ap','bp','cp'] + + Note that since Puppet 4.0.0 the general way to modify values is in array is by using the map + function in Puppet. This example does the same as the example above: + + ['a', 'b', 'c'].map |$x| { "${x}p" } + DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/time.rb b/lib/puppet/parser/functions/time.rb index 021a48381..9f2e3c8c7 100644 --- a/lib/puppet/parser/functions/time.rb +++ b/lib/puppet/parser/functions/time.rb @@ -10,6 +10,13 @@ module Puppet::Parser::Functions time() Will return something like: 1311972653 + + Note that since Puppet 4.8.0 the Puppet language has the data types Timestamp (a point in time) and + Timespan (a duration). The following example is equivalent to calling time() without + any arguments: + + Timestamp() + DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/type.rb b/lib/puppet/parser/functions/type.rb index d9d841ba8..9fcae7a89 100644 --- a/lib/puppet/parser/functions/type.rb +++ b/lib/puppet/parser/functions/type.rb @@ -3,7 +3,7 @@ # module Puppet::Parser::Functions newfunction(:type, :type => :rvalue, :doc => <<-DOC - DEPRECATED: This function will cease to function on Puppet 4; please use type3x() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system. + DEPRECATED: This function will cease to function on Puppet 4; please use type3x() before upgrading to Puppet 4 for backwards-compatibility, or migrate to the new parser's typing system. DOC ) do |args| diff --git a/lib/puppet/parser/functions/type3x.rb b/lib/puppet/parser/functions/type3x.rb index f5b46aa1f..950171d38 100644 --- a/lib/puppet/parser/functions/type3x.rb +++ b/lib/puppet/parser/functions/type3x.rb @@ -3,7 +3,7 @@ # module Puppet::Parser::Functions newfunction(:type3x, :type => :rvalue, :doc => <<-DOC - DEPRECATED: This function will be removed when puppet 3 support is dropped; please migrate to the new parser's typing system. + DEPRECATED: This function will be removed when Puppet 3 support is dropped; please migrate to the new parser's typing system. Returns the type when passed a value. Type can be one of: diff --git a/lib/puppet/parser/functions/upcase.rb b/lib/puppet/parser/functions/upcase.rb index 42e611497..563efe4b5 100644 --- a/lib/puppet/parser/functions/upcase.rb +++ b/lib/puppet/parser/functions/upcase.rb @@ -13,6 +13,9 @@ module Puppet::Parser::Functions Will return: ABCD + + Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core + will be used instead of this function. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/values.rb b/lib/puppet/parser/functions/values.rb index 168da84b6..91a0cb9ad 100644 --- a/lib/puppet/parser/functions/values.rb +++ b/lib/puppet/parser/functions/values.rb @@ -17,6 +17,9 @@ module Puppet::Parser::Functions This example would return: [1,2,3] + + Note: from Puppet 5.5.0, the compatible function with the same name in Puppet core + will be used instead of this function. DOC ) do |arguments| diff --git a/lib/puppet/parser/functions/values_at.rb b/lib/puppet/parser/functions/values_at.rb index 2e075526e..cf53fa060 100644 --- a/lib/puppet/parser/functions/values_at.rb +++ b/lib/puppet/parser/functions/values_at.rb @@ -25,6 +25,13 @@ module Puppet::Parser::Functions values_at(['a','b','c','d','e'], [0, "2-3"]) Would return ['a','c','d']. + + Note that since Puppet 4.0.0 it is possible to slice an array with index and count directly in the language. + A negative value is taken to be "from the end" of the array: + + ['a', 'b', 'c', 'd'][1, 2] # results in ['b', 'c'] + ['a', 'b', 'c', 'd'][2, -1] # results in ['c', 'd'] + ['a', 'b', 'c', 'd'][1, -2] # results in ['b', 'c'] DOC ) do |arguments| diff --git a/spec/acceptance/abs_spec.rb b/spec/acceptance/abs_spec.rb index 78d790f15..e3d904a07 100644 --- a/spec/acceptance/abs_spec.rb +++ b/spec/acceptance/abs_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'abs function' do +describe 'abs function', :if => Puppet::Util::Package.versioncmp(return_puppet_version, '6.0.0') < 0 do describe 'success' do pp1 = <<-DOC $input = '-34.56' diff --git a/spec/acceptance/capitalize_spec.rb b/spec/acceptance/capitalize_spec.rb index ce75645ac..e3081e34c 100644 --- a/spec/acceptance/capitalize_spec.rb +++ b/spec/acceptance/capitalize_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'capitalize function' do +describe 'capitalize function', :if => Puppet::Util::Package.versioncmp(return_puppet_version, '6.0.0') < 0 do describe 'success' do pp1 = <<-DOC $input = 'this is a string' diff --git a/spec/acceptance/ceiling_spec.rb b/spec/acceptance/ceiling_spec.rb index 3f686d249..782096a5f 100644 --- a/spec/acceptance/ceiling_spec.rb +++ b/spec/acceptance/ceiling_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'ceiling function' do +describe 'ceiling function', :if => Puppet::Util::Package.versioncmp(return_puppet_version, '6.0.0') < 0 do describe 'success' do pp1 = <<-DOC $a = 12.8 diff --git a/spec/acceptance/chomp_spec.rb b/spec/acceptance/chomp_spec.rb index ba5e7cbad..7fe9b1bb5 100644 --- a/spec/acceptance/chomp_spec.rb +++ b/spec/acceptance/chomp_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'chomp function' do +describe 'chomp function', :if => Puppet::Util::Package.versioncmp(return_puppet_version, '6.0.0') < 0 do describe 'success' do pp = <<-DOC $input = "test\n" diff --git a/spec/acceptance/chop_spec.rb b/spec/acceptance/chop_spec.rb index 6489c28f1..4def10bae 100644 --- a/spec/acceptance/chop_spec.rb +++ b/spec/acceptance/chop_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'chop function' do +describe 'chop function', :if => Puppet::Util::Package.versioncmp(return_puppet_version, '6.0.0') < 0 do describe 'success' do pp1 = <<-DOC $input = "test" diff --git a/spec/acceptance/downcase_spec.rb b/spec/acceptance/downcase_spec.rb index 2ff55f456..053a16fed 100644 --- a/spec/acceptance/downcase_spec.rb +++ b/spec/acceptance/downcase_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'downcase function' do +describe 'downcase function', :if => Puppet::Util::Package.versioncmp(return_puppet_version, '6.0.0') < 0 do describe 'success' do pp1 = <<-DOC $a = 'AOEU' diff --git a/spec/acceptance/floor_spec.rb b/spec/acceptance/floor_spec.rb index 312eec39a..fde6d8eb9 100644 --- a/spec/acceptance/floor_spec.rb +++ b/spec/acceptance/floor_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'floor function' do +describe 'floor function', :if => Puppet::Util::Package.versioncmp(return_puppet_version, '6.0.0') < 0 do describe 'success' do pp1 = <<-DOC $a = 12.8 diff --git a/spec/acceptance/lstrip_spec.rb b/spec/acceptance/lstrip_spec.rb index fe9c01381..1621c5733 100644 --- a/spec/acceptance/lstrip_spec.rb +++ b/spec/acceptance/lstrip_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'lstrip function' do +describe 'lstrip function', :if => Puppet::Util::Package.versioncmp(return_puppet_version, '6.0.0') < 0 do describe 'success' do pp1 = <<-DOC $a = [" the "," public "," art","galleries "] diff --git a/spec/acceptance/max_spec.rb b/spec/acceptance/max_spec.rb index 94828719a..3958a70b2 100644 --- a/spec/acceptance/max_spec.rb +++ b/spec/acceptance/max_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'max function' do +describe 'max function', :if => Puppet::Util::Package.versioncmp(return_puppet_version, '6.0.0') < 0 do describe 'success' do pp = <<-DOC $o = max("the","public","art","galleries") diff --git a/spec/acceptance/min_spec.rb b/spec/acceptance/min_spec.rb index deb660503..ea9606032 100644 --- a/spec/acceptance/min_spec.rb +++ b/spec/acceptance/min_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'min function' do +describe 'min function', :if => Puppet::Util::Package.versioncmp(return_puppet_version, '6.0.0') < 0 do describe 'success' do pp = <<-DOC $o = min("the","public","art","galleries") diff --git a/spec/acceptance/rstrip_spec.rb b/spec/acceptance/rstrip_spec.rb index 60c5fffae..b7aebda48 100644 --- a/spec/acceptance/rstrip_spec.rb +++ b/spec/acceptance/rstrip_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'rstrip function' do +describe 'rstrip function', :if => Puppet::Util::Package.versioncmp(return_puppet_version, '6.0.0') < 0 do describe 'success' do pp1 = <<-DOC $a = [" the "," public "," art","galleries "] diff --git a/spec/acceptance/size_spec.rb b/spec/acceptance/size_spec.rb index d64e37e25..e84e66523 100644 --- a/spec/acceptance/size_spec.rb +++ b/spec/acceptance/size_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'size function', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do +describe 'size function', :if => Puppet::Util::Package.versioncmp(return_puppet_version, '6.0.0') < 0 do describe 'success' do pp1 = <<-DOC $a = 'discombobulate' diff --git a/spec/acceptance/sort_spec.rb b/spec/acceptance/sort_spec.rb index 561fc68cb..8c4a3ab0d 100644 --- a/spec/acceptance/sort_spec.rb +++ b/spec/acceptance/sort_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'sort function' do +describe 'sort function', :if => Puppet::Util::Package.versioncmp(return_puppet_version, '6.0.0') < 0 do describe 'success' do pp1 = <<-DOC $a = ["the","public","art","galleries"] diff --git a/spec/acceptance/strftime_spec.rb b/spec/acceptance/strftime_spec.rb index eec9a60ba..4ba2c6aa6 100644 --- a/spec/acceptance/strftime_spec.rb +++ b/spec/acceptance/strftime_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'strftime function' do +describe 'strftime function', :if => Puppet::Util::Package.versioncmp(Puppet.version, '4.8.0') < 0 do describe 'success' do pp = <<-DOC $o = strftime('%C') diff --git a/spec/acceptance/strip_spec.rb b/spec/acceptance/strip_spec.rb index 5c4dfbdbd..67a939a85 100644 --- a/spec/acceptance/strip_spec.rb +++ b/spec/acceptance/strip_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'strip function' do +describe 'strip function', :if => Puppet::Util::Package.versioncmp(return_puppet_version, '6.0.0') < 0 do describe 'success' do pp1 = <<-DOC $a = [" the "," public "," art","galleries "] diff --git a/spec/acceptance/upcase_spec.rb b/spec/acceptance/upcase_spec.rb index a93c192ea..fda444b9d 100644 --- a/spec/acceptance/upcase_spec.rb +++ b/spec/acceptance/upcase_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'upcase function' do +describe 'upcase function', :if => Puppet::Util::Package.versioncmp(return_puppet_version, '6.0.0') < 0 do describe 'success' do pp1 = <<-DOC $a = ["wallless", "laparohysterosalpingooophorectomy", "brrr", "goddessship"] diff --git a/spec/functions/abs_spec.rb b/spec/functions/abs_spec.rb index a151a7e93..26e89ab80 100644 --- a/spec/functions/abs_spec.rb +++ b/spec/functions/abs_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'abs' do +describe 'abs', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } describe 'signature validation in puppet3', :unless => RSpec.configuration.puppet_future do diff --git a/spec/functions/camelcase_spec.rb b/spec/functions/camelcase_spec.rb index 92531c30c..e0e4003b7 100644 --- a/spec/functions/camelcase_spec.rb +++ b/spec/functions/camelcase_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'camelcase' do +describe 'camelcase', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) } it { is_expected.to run.with_params(100).and_raise_error(Puppet::ParseError) } diff --git a/spec/functions/capitalize_spec.rb b/spec/functions/capitalize_spec.rb index 8884bb4f0..dd5fc354b 100644 --- a/spec/functions/capitalize_spec.rb +++ b/spec/functions/capitalize_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'capitalize' do +describe 'capitalize', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) } it { is_expected.to run.with_params(100).and_raise_error(Puppet::ParseError) } diff --git a/spec/functions/ceiling_spec.rb b/spec/functions/ceiling_spec.rb index 068272084..8150c6ef6 100644 --- a/spec/functions/ceiling_spec.rb +++ b/spec/functions/ceiling_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'ceiling' do +describe 'ceiling', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) } it { is_expected.to run.with_params('foo').and_raise_error(Puppet::ParseError) } diff --git a/spec/functions/chomp_spec.rb b/spec/functions/chomp_spec.rb index 880157309..e6612e8d3 100644 --- a/spec/functions/chomp_spec.rb +++ b/spec/functions/chomp_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'chomp' do +describe 'chomp', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) } it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) } diff --git a/spec/functions/chop_spec.rb b/spec/functions/chop_spec.rb index d9e18ebe7..b33edb5e8 100644 --- a/spec/functions/chop_spec.rb +++ b/spec/functions/chop_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'chop' do +describe 'chop', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) } it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) } diff --git a/spec/functions/downcase_spec.rb b/spec/functions/downcase_spec.rb index 1cb1f35ad..78bfec210 100644 --- a/spec/functions/downcase_spec.rb +++ b/spec/functions/downcase_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'downcase' do +describe 'downcase', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) } it { is_expected.to run.with_params(100).and_raise_error(Puppet::ParseError) } diff --git a/spec/functions/floor_spec.rb b/spec/functions/floor_spec.rb index c669966ed..07d4ed3a5 100644 --- a/spec/functions/floor_spec.rb +++ b/spec/functions/floor_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'floor' do +describe 'floor', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) } it { is_expected.to run.with_params('foo').and_raise_error(Puppet::ParseError) } diff --git a/spec/functions/lstrip_spec.rb b/spec/functions/lstrip_spec.rb index 7c215d9b4..ab2f6f0c4 100644 --- a/spec/functions/lstrip_spec.rb +++ b/spec/functions/lstrip_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'lstrip' do +describe 'lstrip', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } it { diff --git a/spec/functions/max_spec.rb b/spec/functions/max_spec.rb index bacd2fcd2..88879d19b 100644 --- a/spec/functions/max_spec.rb +++ b/spec/functions/max_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'max' do +describe 'max', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } it { is_expected.to run.with_params(1).and_return(1) } diff --git a/spec/functions/min_spec.rb b/spec/functions/min_spec.rb index 2c325a4eb..9e350d950 100644 --- a/spec/functions/min_spec.rb +++ b/spec/functions/min_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'min' do +describe 'min', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } it { is_expected.to run.with_params(1).and_return(1) } diff --git a/spec/functions/round_spec.rb b/spec/functions/round_spec.rb index af99afdf2..fa8ebd5fa 100644 --- a/spec/functions/round_spec.rb +++ b/spec/functions/round_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'round' do +describe 'round', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params(34.3).and_return(34) } it { is_expected.to run.with_params(-34.3).and_return(-34) } diff --git a/spec/functions/rstrip_spec.rb b/spec/functions/rstrip_spec.rb index c8cbeb1a3..60776d895 100644 --- a/spec/functions/rstrip_spec.rb +++ b/spec/functions/rstrip_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'rstrip' do +describe 'rstrip', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } it { diff --git a/spec/functions/sort_spec.rb b/spec/functions/sort_spec.rb index 7d4660d04..a9bdea3ce 100644 --- a/spec/functions/sort_spec.rb +++ b/spec/functions/sort_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'sort' do +describe 'sort', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do describe 'signature validation' do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } diff --git a/spec/functions/strftime_spec.rb b/spec/functions/strftime_spec.rb index 92a6893ba..73c5c968b 100644 --- a/spec/functions/strftime_spec.rb +++ b/spec/functions/strftime_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'strftime' do +describe 'strftime', :if => Puppet::Util::Package.versioncmp(Puppet.version, '4.8.0') < 0 do it 'exists' do expect(Puppet::Parser::Functions.function('strftime')).to eq('function_strftime') end diff --git a/spec/functions/strip_spec.rb b/spec/functions/strip_spec.rb index e13f33abf..28f8d86f2 100644 --- a/spec/functions/strip_spec.rb +++ b/spec/functions/strip_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'strip' do +describe 'strip', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } it { diff --git a/spec/functions/upcase_spec.rb b/spec/functions/upcase_spec.rb index 183c403aa..5b5e42617 100644 --- a/spec/functions/upcase_spec.rb +++ b/spec/functions/upcase_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'upcase' do +describe 'upcase', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do describe 'signature validation' do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }