extended_stdlib
Version information
This version is compatible with:
- Puppet Enterprise 2023.2.x, 2023.1.x, 2023.0.x, 2021.7.x, 2021.6.x, 2021.5.x, 2021.4.x, 2021.3.x, 2021.2.x, 2021.1.x, 2021.0.x, 2019.8.x, 2019.7.x, 2019.5.x, 2019.4.x, 2019.3.x, 2019.2.x, 2019.1.x, 2019.0.x, 2018.1.x
- Puppet >= 5.5.0 < 8.0.0
- , , ,
Tasks:
- csr_attributes
Start using this module
Add this module to your Puppetfile:
mod 'mschuchard-extended_stdlib', '0.9.1'
Learn more about managing modules with a PuppetfileDocumentation
Extended Stdlib
Overview
This module provides an extra set of extensions and expanded functionality for Puppet modules beyond that which is covered by stdlib
.
Module Description
This Puppet module adds extra facts, functions, types and providers, and plans and tasks to Puppet. These should not overlap with the functionality provided by the stdlib
module. These are also likely to be overall at least slightly less useful than those provided in stdlib
.
Setup
Install the extended_stdlib
module to add the functionality to Puppet. Pluginsync will automatically ensure the functionality prior to the next catalog application.
If you are authoring a module that depends on extended_stdlib
, then be sure to specify dependencies in your metadata.json
.
Usage
These are all automatically loaded by Puppet via pluginsync.
Reference
Please see the Reference for generated documentation.
Facts
subnet
Returns the ipv4-based subnet for the system.
Limitations
The Ruby code is tested primarily with versions synced with Puppet 7 and 8. Compatibility with Ruby versions synced with 5 and 6 is desired, but not guaranteed. Please open an issue if an incompatibility is encountered.
Contributing
Code should pass all current tests. New features should include new tests. Adherence to Ruby and Puppet style standards is expected where not overly onerous or where the check is of dubious cost/benefit.
Please consult the GitHub Project for the current development roadmap.
Reference
Table of Contents
Functions
extended_stdlib::compact
: Returns a hash or array with all of the undef value entries removedextended_stdlib::drop
: Returns an Array containing all but the first num element of the array, where num is a non-negative Integerextended_stdlib::intersect
: Returns true if the array and other_array have at least one element in common, otherwise returns false. Will require Puppet version 8 due toextended_stdlib::minmax
: Returns a new two element Array containing the minimum and maximum values from an array of integersextended_stdlib::none
: Returns a boolean of whether no elements of an array, or array or hash with a lambda block meet a given criterion. Note that the combined bloextended_stdlib::product
: Computes and returns all combinations of elements from all of the Arraysextended_stdlib::sample
: Returns random elements from an Array. Note that the return is non-deterministic.extended_stdlib::subset
: Returns a boolean of whether the first hash is a subset of the second hashextended_stdlib::sum
: Returns the sum of an optional summand with all elements of an Array.extended_stdlib::transpose
: Transposes the rows and columns in an Array of Arrays; the nested Arrays must all be the same size.
Tasks
csr_attributes
: Modifies CSR attributes on a client server.
Functions
extended_stdlib::compact
Type: Ruby 4.x API
Returns a hash or array with all of the undef value entries removed
Examples
Input a hash and return it compacted.
compact({'foo' => 0, 'bar' => undef, 'baz' => 2, 'bat' => undef}) => {'foo' => 0, 'baz' => 2}
Input an array and return it compacted.
compact([undef, 0, undef, 1, undef, 2, undef]) => [0, 1, 2]
extended_stdlib::compact(Variant[Hash, Array] $hash_or_array)
Returns a hash or array with all of the undef value entries removed
Returns: Variant[Hash, Array]
The hash or array with all of the undef value entries removed.
Examples
Input a hash and return it compacted.
compact({'foo' => 0, 'bar' => undef, 'baz' => 2, 'bat' => undef}) => {'foo' => 0, 'baz' => 2}
Input an array and return it compacted.
compact([undef, 0, undef, 1, undef, 2, undef]) => [0, 1, 2]
hash_or_array
Data type: Variant[Hash, Array]
The hash or array from which to remove the undef value entries.
extended_stdlib::drop
Type: Ruby 4.x API
Returns an Array containing all but the first num element of the array, where num is a non-negative Integer
Examples
Remove the first 0, 1, or 2 elements from an array, and return that array.
drop([0, 1, 2, 3, 4, 5], 0) => [0, 1, 2, 3, 4, 5]
drop([0, 1, 2, 3, 4, 5], 1) => [1, 2, 3, 4, 5]
drop([0, 1, 2, 3, 4, 5], 2) => [2, 3, 4, 5]
extended_stdlib::drop(Array $the_array, Integer $num)
Returns an Array containing all but the first num element of the array, where num is a non-negative Integer
Returns: Array
Returns the array with the first num elements removed.
Examples
Remove the first 0, 1, or 2 elements from an array, and return that array.
drop([0, 1, 2, 3, 4, 5], 0) => [0, 1, 2, 3, 4, 5]
drop([0, 1, 2, 3, 4, 5], 1) => [1, 2, 3, 4, 5]
drop([0, 1, 2, 3, 4, 5], 2) => [2, 3, 4, 5]
the_array
Data type: Array
The array to remove the first num elements from.
num
Data type: Integer
The number of first elements to remove from the array.
extended_stdlib::intersect
Type: Ruby 4.x API
Returns true if the array and other_array have at least one element in common, otherwise returns false. Will require Puppet version 8 due to Ruby >= 3.0 requirement.
Examples
Determine if first array and second array intersect.
intersect([1, 2, 3], [3, 4, 5]) => true
intersect([1, 2, 3], [5, 6, 7]) => false
extended_stdlib::intersect(Array $a_array, Array $other_array)
Returns true if the array and other_array have at least one element in common, otherwise returns false. Will require Puppet version 8 due to Ruby >= 3.0 requirement.
Returns: Boolean
Returns whether the two arrays intersect.
Examples
Determine if first array and second array intersect.
intersect([1, 2, 3], [3, 4, 5]) => true
intersect([1, 2, 3], [5, 6, 7]) => false
a_array
Data type: Array
The first array to determine if intersects.
other_array
Data type: Array
The second array to determine if intersects.
extended_stdlib::minmax
Type: Ruby 4.x API
Returns a new two element Array containing the minimum and maximum values from an array of integers
Examples
Return the minimum and maximum elements of an array.
minmax([0, 1, 2]) => [0, 2]
extended_stdlib::minmax(Array[Integer, 2] $the_array)
Returns a new two element Array containing the minimum and maximum values from an array of integers
Returns: Array[Integer, 2]
Returns two element array of integers with minimum and maximum values.
Examples
Return the minimum and maximum elements of an array.
minmax([0, 1, 2]) => [0, 2]
the_array
Data type: Array[Integer, 2]
The array of integers from which to return the minimum and maximum values.
extended_stdlib::none
Type: Ruby 4.x API
Returns a boolean of whether no elements of an array, or array or hash with a lambda block meet a given criterion. Note that the combined block input forms do not have code coverage at the moment.
extended_stdlib::none(Array $the_array)
The extended_stdlib::none function.
Returns: Boolean
Returns whether no elements satisfy a conditional (i.e. every element is falsey).
Examples
Return whether no element of any array is truthy.
none([undef, false]) => true
none([undef, 0, false]) => false
none([]) => true
the_array
Data type: Array
The array containing the elements to test the criterion upon. the_hash The hash containing the entries to test the criterion upon. block The optional lambda block to specify the criterion (otherwise directly tests falsiness).
extended_stdlib::none(Hash[Any, Any] $the_hash, Callable[1,1] &$block)
The extended_stdlib::none function.
Returns: Boolean
the_hash
Data type: Hash[Any, Any]
&block
Data type: Callable[1,1]
extended_stdlib::none(Hash[Any, Any] $the_hash, Callable[2,2] &$block)
The extended_stdlib::none function.
Returns: Boolean
the_hash
Data type: Hash[Any, Any]
&block
Data type: Callable[2,2]
extended_stdlib::none(Iterable $enumerable, Callable[1,1] &$block)
The extended_stdlib::none function.
Returns: Boolean
enumerable
Data type: Iterable
&block
Data type: Callable[1,1]
extended_stdlib::none(Iterable $enumerable, Callable[2,2] &$block)
The extended_stdlib::none function.
Returns: Boolean
enumerable
Data type: Iterable
&block
Data type: Callable[2,2]
extended_stdlib::product
Type: Ruby 4.x API
Computes and returns all combinations of elements from all of the Arrays
Examples
Returns original Array if only one is specified.
product([[0, 1, 2]]) => [[0, 1, 2]]
Return the product of two Arrays.
product([[0, 1, 2], [3, 4]]) => [[0, 3], [0, 4], [1, 3], [1, 4], [2, 3], [2, 4]]
Return the product of three Arrays.
product([[0, 1, 2], [3, 4], [5, 6]]) => [[0, 3, 5], [0, 3, 6], [0, 4, 5], [0, 4, 6], [1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], [2, 4, 5], [2, 4, 6]]
extended_stdlib::product(Array *$arrays)
Computes and returns all combinations of elements from all of the Arrays
Returns: Array[Array]
The nested Array containing the product of the Arrays' elements.
Examples
Returns original Array if only one is specified.
product([[0, 1, 2]]) => [[0, 1, 2]]
Return the product of two Arrays.
product([[0, 1, 2], [3, 4]]) => [[0, 3], [0, 4], [1, 3], [1, 4], [2, 3], [2, 4]]
Return the product of three Arrays.
product([[0, 1, 2], [3, 4], [5, 6]]) => [[0, 3, 5], [0, 3, 6], [0, 4, 5], [0, 4, 6], [1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], [2, 4, 5], [2, 4, 6]]
*arrays
Data type: Array
One or more Arrays of which to compute the products. Issue with required_repeated_param in Puppet requires this to be nested Array.
extended_stdlib::sample
Type: Ruby 4.x API
Returns random elements from an Array. Note that the return is non-deterministic.
Examples
Return a random element from an Array.
sample([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) => 3
Return multiple random elements from an Array.
sample([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3) => [8, 9, 2]
sample([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 6) => [9, 6, 10, 3, 1, 4]
extended_stdlib::sample(Array[1] $the_array, Optional[Integer] $num_elements)
Returns random elements from an Array. Note that the return is non-deterministic.
Returns: Variant[Array, Any]
The random element or Array of random elements selected from the Array.
Examples
Return a random element from an Array.
sample([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) => 3
Return multiple random elements from an Array.
sample([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3) => [8, 9, 2]
sample([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 6) => [9, 6, 10, 3, 1, 4]
the_array
Data type: Array[1]
The Array from which to select random elements.
num_elements
Data type: Optional[Integer]
The number of random elements to select from the Array.
extended_stdlib::subset
Type: Ruby 4.x API
Returns a boolean of whether the first hash is a subset of the second hash
Examples
Determine if hash is subset of other_hash.
subset({'foo' => 0, 'bar' => 1}, {'foo' => 0, 'bar' => 1, 'baz' => 2}) => true
subset({'foo' => 0, 'bar' => 1, 'baz' => 2}, {'foo' => 0, 'bar' => 1}) => false
subset({'foo' => 0, 'bar' => 1}, {'foo' => 0, 'bar' => 1}) => true
subset({'foo' => 0, 'bar' => 1}, {'foo' => 0, 'bar' => 1}, true) => false
extended_stdlib::subset(Hash $a_hash, Hash $other_hash, Optional[Boolean] $proper)
Returns a boolean of whether the first hash is a subset of the second hash
Returns: Boolean
Returns whether hash is a subset of other_hash.
Examples
Determine if hash is subset of other_hash.
subset({'foo' => 0, 'bar' => 1}, {'foo' => 0, 'bar' => 1, 'baz' => 2}) => true
subset({'foo' => 0, 'bar' => 1, 'baz' => 2}, {'foo' => 0, 'bar' => 1}) => false
subset({'foo' => 0, 'bar' => 1}, {'foo' => 0, 'bar' => 1}) => true
subset({'foo' => 0, 'bar' => 1}, {'foo' => 0, 'bar' => 1}, true) => false
a_hash
Data type: Hash
The hash to determine if this hash is a subset of other_hash.
other_hash
Data type: Hash
The hash to determine if hash is a subset of this hash.
proper
Data type: Optional[Boolean]
Specifies if the subset determination should be for a proper subset or regular subset.
extended_stdlib::sum
Type: Ruby 4.x API
Returns the sum of an optional summand with all elements of an Array.
Examples
Returns sum of Array of Integers.
sum([0, 1, 2, 3]) => 6
Returns sum of Integer and Array of Integers.
sum([0, 1, 2, 3], 100) => 106
Returns sum of String and Array of Strings.
sum(['abc', 'def', 'ghi'], 'jkl') => 'jklabcdefghi'
extended_stdlib::sum(Array[Variant[Numeric, String]] $the_array, Optional[Variant[Numeric, String]] $summand)
Returns the sum of an optional summand with all elements of an Array.
Returns: Variant[Numeric, String]
Examples
Returns sum of Array of Integers.
sum([0, 1, 2, 3]) => 6
Returns sum of Integer and Array of Integers.
sum([0, 1, 2, 3], 100) => 106
Returns sum of String and Array of Strings.
sum(['abc', 'def', 'ghi'], 'jkl') => 'jklabcdefghi'
the_array
Data type: Array[Variant[Numeric, String]]
The array to sum with an optional summand.
summand
Data type: Optional[Variant[Numeric, String]]
The optional summand to sum with the Array elements.
extended_stdlib::transpose
Type: Ruby 4.x API
Transposes the rows and columns in an Array of Arrays; the nested Arrays must all be the same size.
Examples
Returns 1x2 transposition of 2x1 nested Array.
transpose([['a0', 'a1']]) => [['a0'], ['a1']]
Returns 3x2 transposition of 2x3 nested Array.
transpose([['a0', 'a1'], ['b0', 'b1'], ['c0', 'c1']]) => [['a0', 'b0', 'c0'], ['a1', 'b1', 'c1']]
extended_stdlib::transpose(Array *$arrays)
Transposes the rows and columns in an Array of Arrays; the nested Arrays must all be the same size.
Returns: Array[Array]
The nested Array containing the transposition of the Arrays' elements.
Examples
Returns 1x2 transposition of 2x1 nested Array.
transpose([['a0', 'a1']]) => [['a0'], ['a1']]
Returns 3x2 transposition of 2x3 nested Array.
transpose([['a0', 'a1'], ['b0', 'b1'], ['c0', 'c1']]) => [['a0', 'b0', 'c0'], ['a1', 'b1', 'c1']]
*arrays
Data type: Array
One or more equal-size Arrays of which to transpose. Issue with required_repeated_param in Puppet requires this to be nested Array.
Tasks
csr_attributes
Modifies CSR attributes on a client server.
Supports noop? false
Parameters
extension_requests
Data type: Hash
The desired extension requests (permanent data to be embedded in a signed certificate). Note that input values will overwrite current values with the same paired key.
custom_attributes
Data type: Hash
The desired custom attributes (transient data used for pre-validating requests). Note that input values will overwrite current values with the same paired key.
purge_extension_requests
Data type: Boolean
Whether or not to purge the existing extension requests in the CSR attributes when updating.
purge_custom_attributes
Data type: Boolean
Whether or not to purge the existing custom attributes in the CSR attributes instead when updating.
What are tasks?
Modules can contain tasks that take action outside of a desired state managed by Puppet. It’s perfect for troubleshooting or deploying one-off changes, distributing scripts to run across your infrastructure, or automating changes that need to happen in a particular order as part of an application deployment.
Tasks in this module release
0.9.1
- Second beta release.
0.9.0
- Initial beta release.