extlib

extlib provides functions out of scope puppetlabs/stdlib

4,163,904 downloads

3,469 latest version

5.0 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Version information

  • 7.5.1 (latest)
  • 7.5.0
  • 7.4.0
  • 7.3.0
  • 7.2.0
  • 7.1.0
  • 7.0.0
  • 6.2.0
  • 6.1.0
  • 6.0.0
  • 5.3.0
  • 5.2.1
  • 5.2.0
  • 5.1.0
  • 5.0.0
  • 4.2.0
  • 4.1.0
  • 4.0.0
  • 3.1.0
  • 3.0.0
  • 2.3.1
  • 2.3.0
  • 2.2.0
  • 2.1.0
  • 2.0.1
  • 2.0.0
  • 1.1.0
  • 1.0.0
  • 0.11.3
  • 0.11.2-rc0 (pre-release)
  • 0.11.1
  • 0.11.0
  • 0.10.7
  • 0.10.6-rc0 (pre-release)
  • 0.10.4
  • 0.9.3
released Jul 24th 2018
This version is compatible with:
  • Puppet Enterprise 2018.1.x, 2017.3.x, 2017.2.x, 2016.4.x
  • Puppet >= 4.10.0 < 6.0.0
  • , , , ,

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'puppet-extlib', '2.2.0'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add puppet-extlib
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install puppet-extlib --version 2.2.0

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download

Documentation

puppet/extlib — version 2.2.0 Jul 24th 2018

Reference

Table of Contents

Functions

  • cache_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 generate
  • default_content: Takes an optional content and an optional template name and returns the contents of a file. Examples: $config_file_content = default_co
  • dump_args: dump_args - prints the args to STDOUT in Pretty JSON format. Useful for debugging purposes only. Ideally you would use this in conjunction w
  • echo: This function output the variable content and its type to the debug log. It's similiar to the "notice" function but provides a better output
  • extlib::has_module: A function that lets you know whether a specific module is on your modulepath.
  • extlib::sort_by_version: A function that sorts an array of version numbers
  • ip_to_cron:
  • random_password: Returns a string of arbitrary length that contains randomly selected characters. Prototype: random_password(n) Where n is a non-negati
  • resources_deep_merge: Deeply merge a "defaults" hash into a "resources" hash like the ones expected by create_resources(). Internally calls the puppetlabs-stdlib f

Functions

cache_data

Type: Ruby 3.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.

Usage: cache_data(namespace, name, initial_data) Example: $password = cache_data('mysql', 'mysql_password', 'this_is_my_password')

cache_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.

Usage: cache_data(namespace, name, initial_data) Example: $password = cache_data('mysql', 'mysql_password', 'this_is_my_password')

Returns: Any

default_content

Type: Ruby 3.x API

Takes an optional content and an optional template name and returns the contents of a file.

Examples:

$config_file_content = default_content($file_content, $template_location)
file { '/tmp/x':
  ensure  => 'file',
  content => $config_file_content,
}

default_content()

Takes an optional content and an optional template name and returns the contents of a file.

Examples:

$config_file_content = default_content($file_content, $template_location)
file { '/tmp/x':
  ensure  => 'file',
  content => $config_file_content,
}

Returns: Any

dump_args

Type: Ruby 3.x API

dump_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.

dump_args()

dump_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: Any

echo

Type: Ruby 3.x API

This function output 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.

Example: $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"

echo()

This function output 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.

Example: $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: Any

extlib::has_module

Type: Ruby 4.x API

A function that lets you know whether a specific module is on your modulepath.

extlib::has_module(Pattern[/\A\w+[-\/]\w+\z/] $module_name)

The extlib::has_module function.

Returns: Boolean Returns true or false.

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::sort_by_version

Type: Ruby 4.x API

A function that sorts an array of version numbers

extlib::sort_by_version(Array[String] $versions)

The extlib::sort_by_version function.

Returns: Array Returns the sorted array.

versions

Data type: Array[String]

An array of version strings you want sorted

ip_to_cron

Type: Ruby 3.x API

The ip_to_cron function.

ip_to_cron()

The ip_to_cron function.

Returns: Any

random_password

Type: Ruby 3.x API

Returns a string of arbitrary length that contains randomly selected characters.

Prototype:

random_password(n)

Where n is a non-negative numeric value that denotes length of the desired password.

For example:

Given the following statements:

$a = 4
$b = 8
$c = 16

notice random_password($a)
notice random_password($b)
notice random_password($c)

The result will be as follows:

notice: Scope(Class[main]): fNDC
notice: Scope(Class[main]): KcKDLrjR
notice: Scope(Class[main]): FtvfvkS9j9wXLsd6

random_password()

Returns a string of arbitrary length that contains randomly selected characters.

Prototype:

random_password(n)

Where n is a non-negative numeric value that denotes length of the desired password.

For example:

Given the following statements:

$a = 4
$b = 8
$c = 16

notice random_password($a)
notice random_password($b)
notice random_password($c)

The result will be as follows:

notice: Scope(Class[main]): fNDC
notice: Scope(Class[main]): KcKDLrjR
notice: Scope(Class[main]): FtvfvkS9j9wXLsd6

Returns: Any

resources_deep_merge

Type: Ruby 3.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',

}

}

}

resources_deep_merge()

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: Any