Version information
This version is compatible with:
- Puppet Enterprise 2023.8.x, 2023.7.x, 2023.6.x, 2023.5.x, 2023.4.x, 2023.3.x, 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
- Puppet >= 7.0.0 < 9.0.0
- , , , , ,
Start using this module
Add this module to your Puppetfile:
mod 'puppet-extlib', '7.3.0'
Learn more about managing modules with a PuppetfileDocumentation
Extlib module for Puppet
Table of Contents
- Overview
- Setup - The basics of getting started with extlib
- Usage - Configuration options and additional functionality
- Limitations - OS compatibility, etc.
- Development - Guide for contributing to the module
Overview
This module provides functions and facts that are out of scope for stdlib. Some of them are even intrinsically tied to stdlib.
Setup
% puppet module install puppet-extlib
Usage
Since puppet/extlib
version 3, all functions are provided under the extlib
namespace.
Non namespaced versions were removed in version 5.
All functions are documented in REFERENCE.md
Facts
All facts in this module are namespaced and begin extlib__
.
Facter 4 users can also find all facts under a single extlib
toplevel
structured fact.
extlib__puppet_config
(or extlib['puppet_config']
when using facter 4)
A fact to expose puppet.conf settings. These are resolved on the agent, (unlike
$settings::<setting_name>
which is resolved on the puppet master).
The following sections/settings are included.
{
main => {
hostpubkey,
hostprivkey,
hostcert,
localcacert,
ssldir,
vardir,
server,
},
master => {
localcacert,
ssldir,
}
}
Limitations
Some functions require puppetlabs-stdlib (>= 4.6.0) and all functions are only compatible with Puppet 4.7 and later.
Development
We highly welcome new contributions to this module, especially those that include documentation, and rspec tests ;) but will happily guide you through the process, so, yes, please submit that pull request!
Reference documentation is generated using puppet-strings. To regenerate it, please run the rake task as follows.
bundle exec rake reference
Reference
Table of Contents
Functions
extlib::cache_data
: Retrieves data from a cache file, or creates it with supplied data if the file doesn't existextlib::cidr_to_netmask
: Converts an CIDR address of the form 192.168.0.1/24 into its netmask.extlib::cidr_to_network
: Converts a CIDR address of the form 2001:DB8::/32 or 192.0.2.0/24 into their network address (also known as net address)extlib::compare_ip
: A function that compares two IP addresses. To be used with the built-in sort() function.extlib::default_content
: Takes an optional content and an optional template name and returns the contents of a file.extlib::dir_clean
: Take a path and normalise it to its Unix form.extlib::dir_split
: Splits the given directory or directories into individual paths.extlib::dump_args
: Prints the args to STDOUT in Pretty JSON format.extlib::dump_params
: this function is used to get a list of parameters passed to or resource.extlib::echo
: This function outputs the variable content and its type to the debug log. It's similiar to thenotice
function but provides a better outputextlib::file_separator
: Returns the os specific file path separator.extlib::has_module
: A function that lets you know whether a specific module is on your modulepath.extlib::ip_to_cron
: Provides a "random" value to cron based on the last bit of the machine IP address. used to avoid starting a certain cron job at the same timeextlib::ip_to_reverse
: Returns the reverse of an IP addressextlib::is_in_cidr
: Returns a boolean indicating whether an IP address is part of a network CIDRextlib::last_in_cidr
: Converts an IPv4 or IPv6 CIDR address of the form 192.0.2.1/24 or 2001:db8::1/64 into the last address in the networkextlib::mkdir_p
: Like the unix command mkdir_p except with puppet code.extlib::netmask_to_cidr
: Converts an octet netmask address of the form 255.255.255.0 into its CIDR variant. Thus making it directly usable with the values from facter.extlib::path_join
: Take one or more paths and join them togetherextlib::random_password
: A function to return a string of arbitrary length that contains randomly selected characters.extlib::read_url
: Fetch a string from a URL (should only be used with 'small' remote files). This function should only be used with trusted/internal sources.extlib::resources_deep_merge
: Deeply merge a "defaults" hash into a "resources" hash like the ones expected bycreate_resources()
.extlib::sort_by_version
: A function that sorts an array of version numbers.extlib::to_ini
: This converts a puppet hash to an INI string.
Based on https://github.com/mmckinst/puppet-hash2stuff/blob/master/lib/puppet/parser/functions/hash2ini.rb
Functions
extlib::cache_data
Type: Ruby 4.x API
Retrieves data from a cache file, or creates it with supplied data if the file doesn't exist
Useful for having data that's randomly generated once on the master side (e.g. a password), but then stays the same on subsequent runs. Because it's stored on the master on disk, it doesn't work when you use mulitple Puppet masters that don't share their vardir.
Examples
Calling the function
$password = cache_data('mysql', 'mysql_password', 'this_is_my_password')
With a random password
$password = cache_data('mysql', 'mysql_password', random_password())
extlib::cache_data(String[1] $namespace, String[1] $name, Any $initial_data)
Retrieves data from a cache file, or creates it with supplied data if the file doesn't exist
Useful for having data that's randomly generated once on the master side (e.g. a password), but then stays the same on subsequent runs. Because it's stored on the master on disk, it doesn't work when you use mulitple Puppet masters that don't share their vardir.
Returns: Any
The cached value when it exists. The initial data when no cache exists
Examples
Calling the function
$password = cache_data('mysql', 'mysql_password', 'this_is_my_password')
With a random password
$password = cache_data('mysql', 'mysql_password', random_password())
namespace
Data type: String[1]
Namespace for the cache
name
Data type: String[1]
Cache key within the namespace
initial_data
Data type: Any
The data for when there is no cache yet
extlib::cidr_to_netmask
Type: Ruby 4.x API
Imported by Tim 'bastelfreak' Meusel into voxpupuli/extlib because Yelp/netstdlib got abandoned
Examples
calling the function
extlib::cidr_to_netmask('127.0.0.1/8')
extlib::cidr_to_netmask(Variant[Stdlib::IP::Address::V4::CIDR,Stdlib::IP::Address::V6::CIDR] $ip)
Imported by Tim 'bastelfreak' Meusel into voxpupuli/extlib because Yelp/netstdlib got abandoned
Returns: Variant[Stdlib::IP::Address::V4::Nosubnet,Stdlib::IP::Address::V6::Nosubnet]
IPv6 or IPv4 netmask address
Examples
calling the function
extlib::cidr_to_netmask('127.0.0.1/8')
ip
Data type: Variant[Stdlib::IP::Address::V4::CIDR,Stdlib::IP::Address::V6::CIDR]
IPv6 or IPv4 address in CIDR notation
extlib::cidr_to_network
Type: Ruby 4.x API
Imported by Tim 'bastelfreak' Meusel into voxpupuli/extlib because Yelp/netstdlib got abandoned
Examples
calling the function
extlib::cidr_to_network('2001:DB8::/32')
extlib::cidr_to_network(Variant[Stdlib::IP::Address::V4::CIDR,Stdlib::IP::Address::V6::CIDR] $ip)
Imported by Tim 'bastelfreak' Meusel into voxpupuli/extlib because Yelp/netstdlib got abandoned
Returns: Variant[Stdlib::IP::Address::V4::Nosubnet,Stdlib::IP::Address::V6::Nosubnet]
IPv6 or IPv4 network/net address
Examples
calling the function
extlib::cidr_to_network('2001:DB8::/32')
ip
Data type: Variant[Stdlib::IP::Address::V4::CIDR,Stdlib::IP::Address::V6::CIDR]
IPv6 or IPv4 address in CIDR notation
extlib::compare_ip
Type: Ruby 4.x API
A function that compares two IP addresses. To be used with the built-in sort() function.
Examples
Sorting the array of IP addresses
$ip_addresses = ['10.1.1.1', '10.10.1.1', '10.2.1.1']
$ip_addresses.sort |$a, $b| { extlib::compare_ip($a, $b) }
extlib::compare_ip(Stdlib::IP::Address $left, Stdlib::IP::Address $right)
A function that compares two IP addresses. To be used with the built-in sort() function.
Returns: Integer[-1,1]
-1, 0 or 1 if left value is lesser, equal or greater than right value
Examples
Sorting the array of IP addresses
$ip_addresses = ['10.1.1.1', '10.10.1.1', '10.2.1.1']
$ip_addresses.sort |$a, $b| { extlib::compare_ip($a, $b) }
left
Data type: Stdlib::IP::Address
Left value
right
Data type: Stdlib::IP::Address
Right value
extlib::default_content
Type: Ruby 4.x API
Takes an optional content and an optional template name and returns the contents of a file.
Examples
Using the function with a file resource.
$config_file_content = default_content($file_content, $template_location)
file { '/tmp/x':
ensure => 'file',
content => $config_file_content,
}
extlib::default_content(Optional[String] $content, Optional[String] $template_name)
Takes an optional content and an optional template name and returns the contents of a file.
Returns: Optional[String]
Returns the value of the content parameter if it's a non empty string.
Otherwise returns the rendered output from template_name
.
Returns undef
if both content
and template_name
are undef
.
Examples
Using the function with a file resource.
$config_file_content = default_content($file_content, $template_location)
file { '/tmp/x':
ensure => 'file',
content => $config_file_content,
}
content
Data type: Optional[String]
template_name
Data type: Optional[String]
The path to an .erb or .epp template file or undef
.
extlib::dir_clean
Type: Puppet Language
Instead of having to deal with the different separators between Unix and Windows this function instead formats Windows paths a equivalent Unix like path.
$dir is defined as a Variant to support cleaning 'c:' which is not a valid Stdlib::Absolutepath
Examples
clean Unix paths to return /tmp/test/libs
(i.e. noop)
extlib::dir_clean('/tmp/test/libs')
Clean Windows paths to return /c/test/libs
extlib::dir_clean('c:\\'test\\libs')
extlib::dir_clean(Variant[Stdlib::Absolutepath, Pattern[/\A[a-zA-Z]:\z/]] $dir)
Instead of having to deal with the different separators between Unix and Windows this function instead formats Windows paths a equivalent Unix like path.
$dir is defined as a Variant to support cleaning 'c:' which is not a valid Stdlib::Absolutepath
Returns: Stdlib::Unixpath
Stdlib::Unixpath The cleaned path
Examples
clean Unix paths to return /tmp/test/libs
(i.e. noop)
extlib::dir_clean('/tmp/test/libs')
Clean Windows paths to return /c/test/libs
extlib::dir_clean('c:\\'test\\libs')
dir
Data type: Variant[Stdlib::Absolutepath, Pattern[/\A[a-zA-Z]:\z/]]
The path to clean
extlib::dir_split
Type: Puppet Language
Use this function when you need to split a absolute path into multiple absolute paths that all descend from the given path.
Examples
calling the function
extlib::dir_split('/opt/puppetlabs') => ['/opt', '/opt/puppetlabs']
extlib::dir_split(Variant[Stdlib::Absolutepath, Array[Stdlib::Absolutepath]] $dirs)
Use this function when you need to split a absolute path into multiple absolute paths that all descend from the given path.
Returns: Array[String]
- an array of absolute paths after being cut into individual paths.
Examples
calling the function
extlib::dir_split('/opt/puppetlabs') => ['/opt', '/opt/puppetlabs']
dirs
Data type: Variant[Stdlib::Absolutepath, Array[Stdlib::Absolutepath]]
- either an absolute path or a array of absolute paths.
extlib::dump_args
Type: Ruby 4.x API
Prints the args to STDOUT in Pretty JSON format.
Useful for debugging purposes only. Ideally you would use this in conjunction with a rspec-puppet unit test. Otherwise the output will be shown during a puppet run when verbose/debug options are enabled.
extlib::dump_args(Any $args)
Prints the args to STDOUT in Pretty JSON format.
Useful for debugging purposes only. Ideally you would use this in conjunction with a rspec-puppet unit test. Otherwise the output will be shown during a puppet run when verbose/debug options are enabled.
Returns: Undef
Returns nothing.
args
Data type: Any
The data you want to dump as pretty JSON.
extlib::dump_params
Type: Ruby 4.x API
this function is used to get a list of parameters passed to or resource.
Examples
Passing Parameters from a profile straight though to a base class
class profile::foobar ($param1, $param2) {
class { 'foobar':
* => extlib::dump_params,
additional_param => 'foobar',
}
}
Passing parameters directly to a config file.
class foobar ($app_param1, $app_param2, $class_param1) {
file { '/etc/foo/config.yaml':
ensure => file,
# class param and name are not understoof by the foo app
content => extlib::dump_params(['name', 'class_param1']).to_yaml
}
}
extlib::dump_params(Optional[Array[String[1]]] $filter_keys)
The extlib::dump_params function.
Returns: Any
Examples
Passing Parameters from a profile straight though to a base class
class profile::foobar ($param1, $param2) {
class { 'foobar':
* => extlib::dump_params,
additional_param => 'foobar',
}
}
Passing parameters directly to a config file.
class foobar ($app_param1, $app_param2, $class_param1) {
file { '/etc/foo/config.yaml':
ensure => file,
# class param and name are not understoof by the foo app
content => extlib::dump_params(['name', 'class_param1']).to_yaml
}
}
filter_keys
Data type: Optional[Array[String[1]]]
an optional parameters of keys to filter out. default value is set to 'name'
extlib::echo
Type: Ruby 4.x API
This function outputs the variable content and its type to the
debug log. It's similiar to the notice
function but provides
a better output format useful to trace variable types and values
in the manifests.
$v1 = 'test'
$v2 = ["1", "2", "3"]
$v3 = {"a"=>"1", "b"=>"2"}
$v4 = true
# $v5 is not defined
$v6 = { "b" => { "b" => [1,2,3], "c" => true, "d" => { 'x' => 'y' }}, 'x' => 'y', 'z' => [1,2,3,4,5,6]}
$v7 = 12345
echo($v1, 'My string')
echo($v2, 'My array')
echo($v3, 'My hash')
echo($v4, 'My boolean')
echo($v5, 'My undef')
echo($v6, 'My structure')
echo($v7) # no comment here
debug log output
My string (String) "test"
My array (Array) ["1", "2", "3"]
My hash (Hash) {"a"=>"1", "b"=>"2"}
My boolean (TrueClass) true
My undef (String) ""
My structure (Hash) {"b"=>{"b"=>["1", "2", "3"], "c"=>true, "d"=>{"x"=>"y"}}, "x"=>"y", "z"=>["1", "2", "3", "4", "5", "6"]}
(String) "12345"
extlib::echo(Any $value, Optional[String] $comment)
This function outputs the variable content and its type to the
debug log. It's similiar to the notice
function but provides
a better output format useful to trace variable types and values
in the manifests.
$v1 = 'test'
$v2 = ["1", "2", "3"]
$v3 = {"a"=>"1", "b"=>"2"}
$v4 = true
# $v5 is not defined
$v6 = { "b" => { "b" => [1,2,3], "c" => true, "d" => { 'x' => 'y' }}, 'x' => 'y', 'z' => [1,2,3,4,5,6]}
$v7 = 12345
echo($v1, 'My string')
echo($v2, 'My array')
echo($v3, 'My hash')
echo($v4, 'My boolean')
echo($v5, 'My undef')
echo($v6, 'My structure')
echo($v7) # no comment here
debug log output
My string (String) "test"
My array (Array) ["1", "2", "3"]
My hash (Hash) {"a"=>"1", "b"=>"2"}
My boolean (TrueClass) true
My undef (String) ""
My structure (Hash) {"b"=>{"b"=>["1", "2", "3"], "c"=>true, "d"=>{"x"=>"y"}}, "x"=>"y", "z"=>["1", "2", "3", "4", "5", "6"]}
(String) "12345"
Returns: Undef
Returns nothing.
value
Data type: Any
The value you want to inspect.
comment
Data type: Optional[String]
An optional comment to prepend to the debug output.
extlib::file_separator
Type: Puppet Language
Returns the os specific file path separator.
Examples
Example of how to use
extlib::file_separator() => '/'
extlib::file_separator()
The extlib::file_separator function.
Returns: String
- The os specific path separator.
Examples
Example of how to use
extlib::file_separator() => '/'
extlib::has_module
Type: Ruby 4.x API
A function that lets you know whether a specific module is on your modulepath.
Examples
Calling the function
extlib::has_module('camptocamp/systemd')
extlib::has_module(Pattern[/\A\w+[-\/]\w+\z/] $module_name)
A function that lets you know whether a specific module is on your modulepath.
Returns: Boolean
Returns true
or false
.
Examples
Calling the function
extlib::has_module('camptocamp/systemd')
module_name
Data type: Pattern[/\A\w+[-\/]\w+\z/]
The full name of the module you want to know exists or not.
Namespace and modulename can be separated with either -
or /
.
extlib::ip_to_cron
Type: Ruby 4.x API
Provides a "random" value to cron based on the last bit of the machine IP address. used to avoid starting a certain cron job at the same time on all servers. Takes the runinterval in seconds as parameter and returns an array of [hour, minute]
example usage
ip_to_cron(3600) - returns [ '*', one value between 0..59 ]
ip_to_cron(1800) - returns [ '*', an array of two values between 0..59 ]
ip_to_cron(7200) - returns [ an array of twelve values between 0..23, one value between 0..59 ]
extlib::ip_to_cron(Optional[Integer[1]] $runinterval)
Provides a "random" value to cron based on the last bit of the machine IP address. used to avoid starting a certain cron job at the same time on all servers. Takes the runinterval in seconds as parameter and returns an array of [hour, minute]
example usage
ip_to_cron(3600) - returns [ '*', one value between 0..59 ]
ip_to_cron(1800) - returns [ '*', an array of two values between 0..59 ]
ip_to_cron(7200) - returns [ an array of twelve values between 0..23, one value between 0..59 ]
Returns: Array
runinterval
Data type: Optional[Integer[1]]
The number of seconds to use as the run interval
extlib::ip_to_reverse
Type: Ruby 4.x API
No actual query is done to the DNS server, it only calculate the record that could be added to a DNS zone file.
If you want to effectively make a query, see Vox Pupuli dns-query module: https://github.com/voxpupuli/puppet-dnsquery
Examples
Calling the function
extlib::ip_to_reverse('192.0.2.0')
extlib::ip_to_reverse(Stdlib::IP::Address $ip)
No actual query is done to the DNS server, it only calculate the record that could be added to a DNS zone file.
If you want to effectively make a query, see Vox Pupuli dns-query module: https://github.com/voxpupuli/puppet-dnsquery
Returns: String
Examples
Calling the function
extlib::ip_to_reverse('192.0.2.0')
ip
Data type: Stdlib::IP::Address
IPv4 or IPv6 address
extlib::is_in_cidr
Type: Ruby 4.x API
Returns a boolean indicating whether an IP address is part of a network CIDR
Examples
Calling the function
'192.0.2.42'.extlib::is_in_cidr('192.0.2.0/24')
extlib::is_in_cidr(Stdlib::IP::Address::Nosubnet $ip, Variant[Stdlib::IP::Address::V4::CIDR,Stdlib::IP::Address::V6::CIDR] $cidr)
The extlib::is_in_cidr function.
Returns: Boolean
Examples
Calling the function
'192.0.2.42'.extlib::is_in_cidr('192.0.2.0/24')
ip
Data type: Stdlib::IP::Address::Nosubnet
IPv4 or IPv6 address
cidr
Data type: Variant[Stdlib::IP::Address::V4::CIDR,Stdlib::IP::Address::V6::CIDR]
CIDR you want to check whether the IP address is in or not
extlib::last_in_cidr
Type: Ruby 4.x API
Imported by Tim 'bastelfreak' Meusel into voxpupuli/extlib because Yelp/netstdlib got abandoned
Examples
calling the function
extlib::last_in_cidr('127.0.0.1/8')
extlib::last_in_cidr(Variant[Stdlib::IP::Address::V4::CIDR,Stdlib::IP::Address::V6::CIDR] $ip)
Imported by Tim 'bastelfreak' Meusel into voxpupuli/extlib because Yelp/netstdlib got abandoned
Returns: Variant[Stdlib::IP::Address::V4::Nosubnet,Stdlib::IP::Address::V6::Nosubnet]
last address in the network
Examples
calling the function
extlib::last_in_cidr('127.0.0.1/8')
ip
Data type: Variant[Stdlib::IP::Address::V4::CIDR,Stdlib::IP::Address::V6::CIDR]
IP address in CIDR notation
extlib::mkdir_p
Type: Puppet Language
This creates file resources for all directories and utilizes the dir_split() function to get a list of all the descendant directories. You will have no control over any other parameters for the file resource. If you wish to control the file resources you can use the dir_split() function and get an array of directories for use in your own code. Please note this does not use an exec resource.
- Note splits the given directories into paths that are then created using file resources
Examples
How to use
extlib::mkdir_p('/opt/puppetlabs/bin') => ['/opt', '/opt/puppetlabs', '/opt/puppetlabs/bin']
extlib::mkdir_p(Variant[Stdlib::Absolutepath, Array[Stdlib::Absolutepath]] $dirs)
This creates file resources for all directories and utilizes the dir_split() function to get a list of all the descendant directories. You will have no control over any other parameters for the file resource. If you wish to control the file resources you can use the dir_split() function and get an array of directories for use in your own code. Please note this does not use an exec resource.
Returns: Array[Stdlib::Absolutepath]
Examples
How to use
extlib::mkdir_p('/opt/puppetlabs/bin') => ['/opt', '/opt/puppetlabs', '/opt/puppetlabs/bin']
dirs
Data type: Variant[Stdlib::Absolutepath, Array[Stdlib::Absolutepath]]
- the path(s) to create
extlib::netmask_to_cidr
Type: Ruby 4.x API
Converts an octet netmask address of the form 255.255.255.0 into its CIDR variant. Thus making it directly usable with the values from facter.
Examples
calling the function
extlib::netmask_to_cidr('255.0.0.0')
extlib::netmask_to_cidr(Stdlib::IP::Address::Nosubnet $netmask)
The extlib::netmask_to_cidr function.
Returns: Integer[0, 128]
CIDR / prefix length
Examples
calling the function
extlib::netmask_to_cidr('255.0.0.0')
netmask
Data type: Stdlib::IP::Address::Nosubnet
IPv6 or IPv4 netmask in octet notation
extlib::path_join
Type: Puppet Language
This function will format a windows paths into equivalent unix like paths. This type of unix like path should work on windows.
Examples
Joining Unix paths to return /tmp/test/libs
extlib::path_join(['/tmp', 'test', 'libs'])
Joining Windows paths to return /c/test/libs
extlib::path_join(['c:', 'test', 'libs'])
extlib::path_join(Variant[String, Array[String]] $dirs)
This function will format a windows paths into equivalent unix like paths. This type of unix like path should work on windows.
Returns: Stdlib::Absolutepath
The joined path
Examples
Joining Unix paths to return /tmp/test/libs
extlib::path_join(['/tmp', 'test', 'libs'])
Joining Windows paths to return /c/test/libs
extlib::path_join(['c:', 'test', 'libs'])
dirs
Data type: Variant[String, Array[String]]
Joins two or more directories by file separator.
extlib::random_password
Type: Ruby 4.x API
A function to return a string of arbitrary length that contains randomly selected characters.
Examples
Calling the function
random_password(42)
extlib::random_password(Integer[1] $length)
A function to return a string of arbitrary length that contains randomly selected characters.
Returns: String
The random string returned consists of alphanumeric characters excluding 'look-alike' characters.
Examples
Calling the function
random_password(42)
length
Data type: Integer[1]
The length of random password you want generated.
extlib::read_url
Type: Ruby 4.x API
Fetch a string from a URL (should only be used with 'small' remote files).
This function should only be used with trusted/internal sources.
This is especially important if using it in conjunction with inline_template
or inline_epp
.
The current implementation is also very basic. No thought has gone into timeouts,
support for redirects, CA paths etc.
Examples
Calling the function
extlib::read_url('https://example.com/sometemplate.epp')
extlib::read_url(Stdlib::HTTPUrl $url)
Fetch a string from a URL (should only be used with 'small' remote files).
This function should only be used with trusted/internal sources.
This is especially important if using it in conjunction with inline_template
or inline_epp
.
The current implementation is also very basic. No thought has gone into timeouts,
support for redirects, CA paths etc.
Returns: String
Returns the contents of the url as a string
Examples
Calling the function
extlib::read_url('https://example.com/sometemplate.epp')
url
Data type: Stdlib::HTTPUrl
The URL to read from
extlib::resources_deep_merge
Type: Ruby 4.x API
Deeply merge a "defaults" hash into a "resources" hash like the ones expected by create_resources()
.
Internally calls the puppetlabs-stdlib function deep_merge()
. In case of
duplicate keys the resources
hash keys win over the defaults
hash keys.
Example
$defaults_hash = {
'one' => '1',
'two' => '2',
'three' => '3',
'four' => {
'five' => '5',
'six' => '6',
'seven' => '7',
}
}
$numbers_hash = {
'german' => {
'one' => 'eins',
'three' => 'drei',
'four' => {
'six' => 'sechs',
},
},
'french' => {
'one' => 'un',
'two' => 'deux',
'four' => {
'five' => 'cinq',
'seven' => 'sept',
},
}
}
$result_hash = resources_deep_merge($numbers_hash, $defaults_hash)
The $result_hash then looks like this:
$result_hash = {
'german' => {
'one' => 'eins',
'two' => '2',
'three' => 'drei',
'four' => {
'five' => '5',
'six' => 'sechs',
'seven' => '7',
}
},
'french' => {
'one' => 'un',
'two' => 'deux',
'three' => '3',
'four' => {
'five' => 'cinq',
'six' => '6',
'seven' => 'sept',
}
}
}
extlib::resources_deep_merge(Hash $resources, Hash $defaults)
Deeply merge a "defaults" hash into a "resources" hash like the ones expected by create_resources()
.
Internally calls the puppetlabs-stdlib function deep_merge()
. In case of
duplicate keys the resources
hash keys win over the defaults
hash keys.
Example
$defaults_hash = {
'one' => '1',
'two' => '2',
'three' => '3',
'four' => {
'five' => '5',
'six' => '6',
'seven' => '7',
}
}
$numbers_hash = {
'german' => {
'one' => 'eins',
'three' => 'drei',
'four' => {
'six' => 'sechs',
},
},
'french' => {
'one' => 'un',
'two' => 'deux',
'four' => {
'five' => 'cinq',
'seven' => 'sept',
},
}
}
$result_hash = resources_deep_merge($numbers_hash, $defaults_hash)
The $result_hash then looks like this:
$result_hash = {
'german' => {
'one' => 'eins',
'two' => '2',
'three' => 'drei',
'four' => {
'five' => '5',
'six' => 'sechs',
'seven' => '7',
}
},
'french' => {
'one' => 'un',
'two' => 'deux',
'three' => '3',
'four' => {
'five' => 'cinq',
'six' => '6',
'seven' => 'sept',
}
}
}
Returns: Hash
Returns the merged hash.
resources
Data type: Hash
The hash of resources.
defaults
Data type: Hash
The hash of defaults to merge.
extlib::sort_by_version
Type: Ruby 4.x API
A function that sorts an array of version numbers.
Examples
Calling the function
extlib::sort_by_version(['10.0.0b12', '10.0.0b3', '10.0.0a2', '9.0.10', '9.0.3'])
extlib::sort_by_version(Array[String] $versions)
A function that sorts an array of version numbers.
Returns: Array[String]
Returns the sorted array.
Examples
Calling the function
extlib::sort_by_version(['10.0.0b12', '10.0.0b3', '10.0.0a2', '9.0.10', '9.0.3'])
versions
Data type: Array[String]
An array of version strings you want sorted.
extlib::to_ini
Type: Ruby 4.x API
This converts a puppet hash to an INI string.
Based on https://github.com/mmckinst/puppet-hash2stuff/blob/master/lib/puppet/parser/functions/hash2ini.rb
Examples
How to output ini to a file
file { '/tmp/config.ini':
ensure => file,
content => extlib::to_ini($myhash),
}
extlib::to_ini(Hash $data, Optional[Hash] $settings)
The extlib::to_ini function.
Returns: String
Converted data as ini string
Examples
How to output ini to a file
file { '/tmp/config.ini':
ensure => file,
content => extlib::to_ini($myhash),
}
data
Data type: Hash
Data structure which needs to be converted into ini
settings
Data type: Optional[Hash]
Override default ini generation settings
Changelog
All notable changes to this project will be documented in this file. Each new release typically also includes the latest modulesync defaults. These should not affect the functionality of the module.
v7.3.0 (2024-12-09)
Implemented enhancements:
- Add support for EL9 #236 (ghoneycutt)
v7.2.0 (2024-08-01)
Implemented enhancements:
- extlib__puppet_config: Add environment settings #232 (bastelfreak)
v7.1.0 (2024-06-28)
Implemented enhancements:
v7.0.0 (2023-08-19)
Breaking changes:
- Drop Puppet 6 support #210 (bastelfreak)
Implemented enhancements:
- Add Puppet 8 support #213 (bastelfreak)
- Allow puppetlabs-stdlib 9.x #212 (smortex)
v6.2.0 (2023-02-28)
Implemented enhancements:
v6.1.0 (2022-11-16)
Implemented enhancements:
- Add new
is_in_cidr
function #204 (alexjfisher)
v6.0.0 (2022-02-02)
Breaking changes:
- Drop EoL Ubuntu 16.04 #197 (bastelfreak)
- Drop EoL Debian 8/9 #196 (bastelfreak)
- Drop EoL RHEL/CentOS 6 support #195 (bastelfreak)
- Drop EoL Puppet 5 support - (modulesync 5.1.0) #193 (bastelfreak)
Implemented enhancements:
v5.3.0 (2021-10-18)
Implemented enhancements:
v5.2.1 (2021-08-25)
Merged pull requests:
v5.2.0 (2021-08-18)
Implemented enhancements:
- Add cidr_to_network function #167 (bastelfreak)
Merged pull requests:
- Remove namespaced
extlib.puppet_config
fact #182 (alexjfisher)
v5.1.0 (2021-06-01)
Implemented enhancements:
- Mark compatible with puppetlabs/stdlib 7.x #180 (ekohl)
- Support Puppet 7 #179 (mattock)
- Use a shorter syntax to return #178 (ekohl)
- new function dir_clean and refactor #176 (b4ldr)
- Add ability to specify extra args to path functions #175 (logicminds)
- Add cidr_to_netmask function #166 (bastelfreak)
- Add last_in_cidr function #165 (bastelfreak)
- mark Ubuntu 20.04 as supported #161 (mmoll)
Fixed bugs:
Closed issues:
- import add sorted_json function from solarkennedy/puppet-consul #174
Merged pull requests:
- update REFERENCE.md #169 (bastelfreak)
- Remove cache_data helper methods in tests #163 (ekohl)
- Fix several markdown lint issues #160 (dhoppe)
v5.0.0 (2020-03-31)
Breaking changes:
- Rename
puppet_config
fact toextlib__puppet_config
#156 (alexjfisher) - Remove deprecated functions #153 (alexjfisher)
Fixed bugs:
- puppet_config / puppet_settings fact confined to Linux #150
Closed issues:
- Module conflicts with puppetlabs/puppet_agent #148
Merged pull requests:
- Remove strings patterns #155 (ekohl)
- Mark Red Hat 8, CentOS 8 and Debian 10 as supported #154 (ekohl)
- puppet_config: no need to confine to linux #151 (b4ldr)
- update repo links to https #147 (bastelfreak)
v4.2.0 (2020-01-25)
Implemented enhancements:
Merged pull requests:
- Remove duplicate CONTRIBUTING.md file #141 (dhoppe)
- drop Ubuntu 14.04 support #140 (bastelfreak)
v4.1.0 (2019-11-07)
Implemented enhancements:
- Add experimental
extlib::read_url
function #137 (alexjfisher)
v4.0.0 (2019-05-29)
Breaking changes:
- modulesync 2.7.0 & Drop puppet4; require at least Puppet 5.5.8 #132 (bastelfreak)
Implemented enhancements:
- Allow
puppetlabs/stdlib
6.x #134 (alexjfisher) - Add new file based functions #129 (logicminds)
Merged pull requests:
- Improve
extlib::path_join
docs formatting #133 (alexjfisher)
v3.1.0 (2018-12-19)
Implemented enhancements:
- Mark Debian 9 and Ubuntu 18.04 as supported #126 (ekohl)
- allow puppet 6.x and modulesync 2.1.0 #124 (bastelfreak)
v3.0.0 (2018-09-28)
In this release, all functions have been moved to the extlib::
namespace and converted to the 4.X function API. Non name-spaced versions are still available, but deprecated and will be removed in a future major release.
During the conversion work, a couple of functions have minor but technically breaking changes. These are documented below.
Breaking changes:
- Convert
random_password
to API 4 function #112 (alexjfisher) - Convert
ip_to_cron
to API 4 function #111 (alexjfisher)
Closed issues:
Merged pull requests:
- Clean up documentation #121 (alexjfisher)
- Namespace functions #120 (alexjfisher)
- Convert
dump_args
to API 4.x function #118 (alexjfisher) - Use Optional[String] in default_content() #117 (ekohl)
- Convert
resources_deep_merge
to API 4.x function #116 (alexjfisher) - Rewrite cache_data to 4.x API #114 (ekohl)
- Convert
echo
function to 4.x API #109 (alexjfisher) - Fix default_content puppet-strings tags #108 (alexjfisher)
v2.3.1 (2018-08-26)
Merged pull requests:
- allow puppetlabs/stdlib 5.x #106 (bastelfreak)
v2.3.0 (2018-07-29)
Implemented enhancements:
v2.2.0 (2018-07-24)
Implemented enhancements:
- Add sort_by_version function #99 (alexjfisher)
v2.1.0 (2018-06-16)
Implemented enhancements:
- Add has_module function #92 (alexjfisher)
Merged pull requests:
- Remove docker nodesets #96 (bastelfreak)
- drop EOL OSs; fix puppet version range #94 (bastelfreak)
v2.0.1 (2017-12-18)
Merged pull requests:
v2.0.0 (2017-10-11)
Fixed bugs:
v1.1.0 (2017-01-13)
Merged pull requests:
- Bump min version_requirement for Puppet + dep #75 (juniorsysadmin)
- Add missing badges #70 (dhoppe)
v1.0.0 (2016-08-19)
Closed issues:
- Unit tests are spread across 2 directories #60
- ip_to_cron needs unit tests #59
- please make a fresh release #54
Merged pull requests:
- typo #65 (mmckinst)
- Add better ip_to_cron unit tests #62 (alexjfisher)
- Move function spec tests #61 (alexjfisher)
v0.11.3 (2016-04-17)
Merged pull requests:
- bump again #56 (bastelfreak)
v0.11.2 (2016-04-17)
v0.11.1 (2016-04-17)
Closed issues:
- import ip_to_cron #48
Merged pull requests:
- Release 0.11.1 #55 (jyaworski)
- Fixes GH-48: Import ip_to_cron.rb from theforeman/puppet-puppet #52 (jyaworski)
- Pin rake to avoid rubocop/rake 11 incompatibility #51 (roidelapluie)
- rename puppet[ -]?community -> voxpupuli #47 (igalic)
- chore(sync) ensure Rakefile and Gemfile are msynced #46 (igalic)
- Added dump_args statement function for debugging puppet code #30 (logicminds)
v0.11.0 (2015-12-31)
Merged pull requests:
- Release PR for version 0.11.0 #45 (rnelson0)
- fix(default_content) don't call template() on empty template_name #44 (igalic)
v0.10.7 (2015-12-29)
Merged pull requests:
v0.10.6 (2015-12-22)
v0.10.5 (2015-12-21)
Closed issues:
Merged pull requests:
- prepare for 0.10.5 release #38 (igalic)
- docs (default_content) align rdoc and readme #37 (igalic)
- prep 0.10.4 release #35 (igalic)
- feat (release) travis_release now creates -rc version #34 (igalic)
- Puppet 4-safe function calls #31 (igalic)
- fixing 2 typos that bugged me in the readme #29 (ApisMellow)
- Add default_content function #4 (alvagante)
v0.10.3 (2015-10-05)
v0.10.2 (2015-10-05)
0.10.1 (2015-10-05)
v0.10.1 (2015-10-05)
v0.10.0 (2015-10-05)
Closed issues:
- deployment, how does it work!? #10
Merged pull requests:
- prepare release of 0.10.0 #27 (igalic)
- fix Rubocop complaints + rspec deprecations #26 (igalic)
- rubcop:auto_correct #24 (igalic)
- Add random_password function to generate alphanumeric passwords #19 (ehelms)
- Add "echo" function for debugging #18 (dmitryilyin)
- Adds cache_data function for caching values on the master #17 (ehelms)
- "Update Readme for puppet- namechange" #16 (nibalizer)
- "Enable metadata.json linting" #15 (nibalizer)
- Check functions against stdlib #13 (nibalizer)
- document (and simplify) release process #12 (igalic)
- further distill matrix, following @camptocamp's example #11 (igalic)
v0.9.3 (2015-03-17)
Merged pull requests:
- rename module in README, also. #9 (igalic)
- no email plz #8 (nibalizer)
- our forge name is puppet, not puppetcommunity! #7 (igalic)
- test more puppet versions #6 (igalic)
v0.9.2 (2015-03-16)
Merged pull requests:
v0.9.1 (2014-09-03)
Closed issues:
- spec tests to 3.0 #2
Merged pull requests:
v0.9.0 (2014-09-02)
* This Changelog was automatically generated by github_changelog_generator
Dependencies
- puppetlabs/stdlib (>= 4.18.0 < 10.0.0)
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.