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::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::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
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.
$password = cache_data('mysql', 'mysql_password', 'this_is_my_password')
$password = cache_data('mysql', 'mysql_password', random_password())
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
$password = cache_data('mysql', 'mysql_password', 'this_is_my_password')
$password = cache_data('mysql', 'mysql_password', random_password())
Data type: String[1]
Namespace for the cache
Data type: String[1]
Cache key within the namespace
Data type: Any
The data for when there is no cache yet
Type: Ruby 4.x API
Imported by Tim 'bastelfreak' Meusel into voxpupuli/extlib because Yelp/netstdlib got abandoned
extlib::cidr_to_netmask('127.0.0.1/8')
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
extlib::cidr_to_netmask('127.0.0.1/8')
Data type: Variant[Stdlib::IP::Address::V4::CIDR,Stdlib::IP::Address::V6::CIDR]
IPv6 or IPv4 address in CIDR notation
Type: Ruby 4.x API
Imported by Tim 'bastelfreak' Meusel into voxpupuli/extlib because Yelp/netstdlib got abandoned
extlib::cidr_to_network('2001:DB8::/32')
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
extlib::cidr_to_network('2001:DB8::/32')
Data type: Variant[Stdlib::IP::Address::V4::CIDR,Stdlib::IP::Address::V6::CIDR]
IPv6 or IPv4 address in CIDR notation
Type: Ruby 4.x API
Takes an optional content and an optional template name and returns the contents of a file.
$config_file_content = default_content($file_content, $template_location)
file { '/tmp/x':
ensure => 'file',
content => $config_file_content,
}
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
.
$config_file_content = default_content($file_content, $template_location)
file { '/tmp/x':
ensure => 'file',
content => $config_file_content,
}
Data type: Optional[String]
Data type: Optional[String]
The path to an .erb or .epp template file or undef
.
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
extlib::dir_clean('/tmp/test/libs')
extlib::dir_clean('c:\\'test\\libs')
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
extlib::dir_clean('/tmp/test/libs')
extlib::dir_clean('c:\\'test\\libs')
Data type: Variant[Stdlib::Absolutepath, Pattern[/\A[a-zA-Z]:\z/]]
The path to clean
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.
extlib::dir_split('/opt/puppetlabs') => ['/opt', '/opt/puppetlabs']
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.
extlib::dir_split('/opt/puppetlabs') => ['/opt', '/opt/puppetlabs']
Data type: Variant[Stdlib::Absolutepath, Array[Stdlib::Absolutepath]]
- either an absolute path or a array of absolute paths.
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.
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.
Data type: Any
The data you want to dump as pretty JSON.
Type: Ruby 4.x API
this function is used to get a list of parameters passed to or resource.
class profile::foobar ($param1, $param2) {
class { 'foobar':
* => extlib::dump_params,
additional_param => 'foobar',
}
}
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
}
}
The extlib::dump_params function.
Returns: Any
class profile::foobar ($param1, $param2) {
class { 'foobar':
* => extlib::dump_params,
additional_param => 'foobar',
}
}
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
}
}
Data type: Optional[Array[String[1]]]
an optional parameters of keys to filter out. default value is set to 'name'
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"
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.
Data type: Any
The value you want to inspect.
Data type: Optional[String]
An optional comment to prepend to the debug output.
Type: Puppet Language
Returns the os specific file path separator.
extlib::file_separator() => '/'
The extlib::file_separator function.
Returns: String
- The os specific path separator.
extlib::file_separator() => '/'
Type: Ruby 4.x API
A function that lets you know whether a specific module is on your modulepath.
extlib::has_module('camptocamp/systemd')
A function that lets you know whether a specific module is on your modulepath.
Returns: Boolean
Returns true
or false
.
extlib::has_module('camptocamp/systemd')
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 /
.
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 ]
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
Data type: Optional[Integer[1]]
The number of seconds to use as the run interval
Type: Ruby 4.x API
Returns a boolean indicating whether an IP address is part of a network CIDR
'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
'192.0.2.42'.extlib::is_in_cidr('192.0.2.0/24')
Data type: Stdlib::IP::Address::Nosubnet
IPv4 or IPv6 address
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
Type: Ruby 4.x API
Imported by Tim 'bastelfreak' Meusel into voxpupuli/extlib because Yelp/netstdlib got abandoned
extlib::last_in_cidr('127.0.0.1/8')
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
extlib::last_in_cidr('127.0.0.1/8')
Data type: Variant[Stdlib::IP::Address::V4::CIDR,Stdlib::IP::Address::V6::CIDR]
IP address in CIDR notation
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
extlib::mkdir_p('/opt/puppetlabs/bin') => ['/opt', '/opt/puppetlabs', '/opt/puppetlabs/bin']
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]
extlib::mkdir_p('/opt/puppetlabs/bin') => ['/opt', '/opt/puppetlabs', '/opt/puppetlabs/bin']
Data type: Variant[Stdlib::Absolutepath, Array[Stdlib::Absolutepath]]
- the path(s) to create
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.
extlib::netmask_to_cidr('255.0.0.0')
The extlib::netmask_to_cidr function.
Returns: Integer[0, 128]
CIDR / prefix length
extlib::netmask_to_cidr('255.0.0.0')
Data type: Stdlib::IP::Address::Nosubnet
IPv6 or IPv4 netmask in octet notation
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.
extlib::path_join(['/tmp', 'test', 'libs'])
extlib::path_join(['c:', 'test', 'libs'])
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
extlib::path_join(['/tmp', 'test', 'libs'])
extlib::path_join(['c:', 'test', 'libs'])
Data type: Variant[String, Array[String]]
Joins two or more directories by file separator.
Type: Ruby 4.x API
A function to return a string of arbitrary length that contains randomly selected characters.
random_password(42)
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.
random_password(42)
Data type: Integer[1]
The length of random password you want generated.
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.
extlib::read_url('https://example.com/sometemplate.epp')
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
extlib::read_url('https://example.com/sometemplate.epp')
Data type: Stdlib::HTTPUrl
The URL to read from
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',
}
}
}
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.
Data type: Hash
The hash of resources.
Data type: Hash
The hash of defaults to merge.
Type: Ruby 4.x API
A function that sorts an array of version numbers.
extlib::sort_by_version(['10.0.0b12', '10.0.0b3', '10.0.0a2', '9.0.10', '9.0.3'])
A function that sorts an array of version numbers.
Returns: Array[String]
Returns the sorted array.
extlib::sort_by_version(['10.0.0b12', '10.0.0b3', '10.0.0a2', '9.0.10', '9.0.3'])
Data type: Array[String]
An array of version strings you want sorted.
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
file { '/tmp/config.ini':
ensure => file,
content => extlib::to_ini($myhash),
}
The extlib::to_ini function.
Returns: String
Converted data as ini string
file { '/tmp/config.ini':
ensure => file,
content => extlib::to_ini($myhash),
}
Data type: Hash
Data structure which needs to be converted into ini
Data type: Optional[Hash]
Override default ini generation settings