Functions¶
OpenVox has a number of built-in functions for loading external data, iteration, logging, manipulating data, and more. This chapter covers the most important ones; the full list is in the built-in function reference.
Template and file functions¶
epp¶
The epp function loads and evaluates an EPP template from a module's
templates directory:
inline_epp¶
The inline_epp function evaluates a string containing an EPP template:
template¶
The template function loads and evaluates an ERB template from a module's
templates directory:
inline_template¶
The inline_template function evaluates a string containing an ERB template:
file¶
The file function loads a file from a module's files directory:
Logging and failure¶
Logging¶
OpenVox supports a number of functions for logging on the server evaluating Puppet code. Each takes a string argument that is logged at an escalating log level:
fail¶
The fail function causes an immediate catalog compilation failure. Any
parameters passed to the function appear in the resulting stack trace.
Iteration¶
each¶
each is the most common native iteration function. Given an Iterable data
type (such as Array or Hash), each loops over each value and runs a
lambda against it:
each ·
Iterative functions ·
Lambdas
create_resources¶
In older versions of Puppet (pre-Puppet 4) that lacked native iteration, the
create_resources function was used to create resources from a hash:
$pkg = {
'vim' => {
'ensure' => 'installed',
},
'emacs' => {
'ensure' => 'absent',
},
}
create_resources('package', $pkg)
With native iteration, the following replaces the create_resources call:
Flow control¶
OpenVox supports the following functions for exiting a loop:
Functions that take a lambda¶
Declaring classes¶
includeadds a class and its resources to a catalog.requiredeclares a class, but also adds a dependency on the required class.containdeclares a class, including all of its resources as if they were defined in the current class.
Warning
include is the only completely safe way to declare a class from multiple
different classes.
Another way to declare a class is with a resource-like class declaration,
which is useful for explicitly specifying class parameters as resource
attributes:
Like any normal resource, duplicate class declarations cause a catalog
compilation failure.
defined¶
defined determines whether a class, resource type, or variable is available,
or whether a resource is declared in a catalog:
Other functions¶
There are many more built-in functions. A selection: