Interpolation
In Hiera you can insert, or
interpolate, the value of a variable into a string, using the syntax %{variable}
.
Hiera uses interpolation in two places:
- Hierarchies: you can interpolate variables into the
path
,paths
,glob
,globs
,uri
,uris
,datadir
,mapped_paths
, andoptions
of a hierarchy level. This lets each node get a customized version of the hierarchy. - Data: you can use interpolation to avoid repetition. This takes one
of two forms:
- If some value always involves the value of a fact (for example, if you need to specify a mail server and you have one predictably-named mail server per domain), reference the fact directly instead of manually transcribing it.
- If multiple keys need to share the same value, write it out
for one of them and reuse it for the rest with the
lookup
oralias
interpolation functions. This makes it easier to keep data up to date, as you only need to change a given value in one place.
Interpolation token syntax
Interpolation tokens consist of the following:
-
A percent sign (
%
) -
An opening curly brace (
{
) -
One of:
-
A variable name, optionally using key.subkey notation to access a specific member of a hash or array.
-
An interpolation function and its argument.
-
-
A closing curly brace (
}
).
For example, %{trusted.certname}
or %{alias("users")}
.
Hiera interpolates values of Puppet data types and converts them to strings. Note that the exception to this is when using an alias. If the alias is the only thing present, then its value is not converted.
In YAML files, any string containing an interpolation token must be enclosed in quotation marks.