Interpolation

Interpolation allows strings to contain expressions, which can be replaced with their values. You can interpolate any expression that resolves to a value, except for statement-style function calls. You can interpolate expressions in double-quoted strings, and in heredocs with interpolation enabled.

To interpolate an expression, start with a dollar sign and wrap the expression in curly braces, as in: "String content ${<EXPRESSION>} more content".

The dollar sign doesn’t have to have a space in front of it. It can be placed directly after any other character, or at the beginning of the string.

An interpolated expression can include quote marks that would end the string if they occurred outside the interpolation token. For example: "<VirtualHost *:${hiera("http_port")}>".

Preventing interpolation

If you want a string to include a literal sequence that looks like an interpolation token, but you don't want Puppet to try to evaluate it, use a quoting syntax that disables interpolation (single quotes or a non-interpolating heredoc), or escape the dollar sign with \$.

Short forms for variable interpolation

The most common thing to interpolate into a string is the value of a variable. To make this easier, Puppet has some shorter forms of the interpolation syntax:

$myvariable
A variable reference (without curly braces) can be replaced with that variable’s value. This also works with qualified variable names like $myclass::myvariable.
Because this syntax doesn’t have an explicit stopping point (like a closing curly brace), Puppet assumes the variable name is everything between the dollar sign and the first character that couldn’t legally be part of a variable name. (Or the end of the string, if that comes first.)
This means you can’t use this style of interpolation when a value must run up against some other word-like text. And even in some cases where you can use this style, the following style can be clearer.
${myvariable}
A dollar sign followed by a variable name in curly braces can be replaced with that variable’s value. This also works with qualified variable names like ${myclass::myvariable}.
With this syntax, you can follow a variable name with any combination of chained function calls or hash access / array access / substring access expressions. For example:
"Using interface ${::interfaces.split(',')[3]} for broadcast"
However, this doesn’t work if the variable’s name overlaps with a language keyword. For example, if you had a variable called $inherits, you would have to use normal-style interpolation:
"Inheriting ${$inherits.upcase}."

Conversion of interpolated values

Puppet converts the value of any interpolated expression to a string using these rules:

Data typeConversion
StringThe contents of the string, with any quoting syntax removed.
UndefAn empty string.
BooleanThe string 'true' or 'false'.
NumberThe number in decimal notation (base 10). For floats, the value can vary on different platforms. Use the sprintf function for more precise formatting.
ArrayA pair of square brackets ([ and ]) containing the array’s elements, separated by a comma and a space (, ), with no trailing comma. Each element is converted to a string using these rules.
HashA pair of curly braces ({ and }) containing a <KEY> => <VALUE> string for each key-value pair, separated by a comma and a space (, ), with no trailing comma. Each key and value is converted to a string using these rules.
Regular expressionA stringified regular expression.
Resource reference or data typeThe value as a string.