Tips for specifying parameter and variable values
Parameters and variables can be structured as JSON, but, if they can't be parsed as JSON, they're treated as strings.
You can use these data types and syntax to specify parameters and variables:
- Strings (for example,
"centos"
): You can use variable-style syntax, which interpolates the result of referencing a fact (for example,"I live at $ipaddress."
), or expression-style syntax, which interpolates the result of evaluating the embedded expression (for example,${$os"release"}
).Strings must be double-quoted, because single quotes aren't valid JSON.In the console, to provide a value containing a dollar sign that is not part of variable syntax (such as password hashes), you must use a backslash to escape each dollar sign and disable interpolation. For example, the password hash$1$nnkkFwEc$safFMXYaUVfKrDV4FLCm0/
must be escaped as\$1\$nnkkFwEc\$safFMXYaUVfKrDV4FLCm0/
. - Booleans (for example,
true
orfalse
). - Numbers (for example,
123
). - Hashes (for example,
{"a": 1}
).You must use colons, not hash rockets. - Arrays (for example,
["1","2.3"]
).
Variable-style syntax
Variable-style syntax uses a dollar sign ($
) followed
by a Puppet fact name, such as: "I live at
$ipaddress"
Variable-style syntax is interpolated as the value of the fact. For example,
$ipaddress
resolves to the value of the
ipaddress
fact.
$pe_node_groups
endpoint
variable cannot be interpolated when used as a classifier in class variable
values.You can't use indexing in variable-style syntax because the indices are treated as
part of the string literal. For example, given the following fact:
processors => {"count" => 4, "physicalcount" => 1}
, if
you use variable-style syntax to specify $processors[count]
, the
value of the processors
fact is interpolated and followed by
literally [count]
. After interpolation, the final
value is {"count" => 4,"physicalcount" => 1}[count]
.
::
top-level scope indication
because the console is not aware of Puppet variable
scope.Expression-style syntax
Use expression-style syntax when you need to index into a fact (such as
${$os[release]}
), refer to trusted facts (such as "My
name is ${trusted[certname]}"
), or delimit fact names from strings
(such as "My ${os} release"
).
For example, this expression-style syntax accesses an operating system's full release
number: ${$os"release"}
Expression-style syntax uses theses elements in this order:
- An initial dollar sign and curly brace:
${
- A legal Puppet fact name preceded by an optional dollar sign.
- Any number of index expressions. Quotation marks around indices are optional unless the index string contains spaces or square brackets.
- A closing curly brace:
}
Indices in expression-style syntax can be used to refer to trusted facts or to access individual fields in structured facts. Use strings in an index to access keys in a hashmap. If you want to access a particular item or character in an array or string based on the order in which it is listed, you can use a zero-indexed integer.
These are examples of legal expression-style interpolation:
${os}
${$os}
${$os[release]}
${$os['release']}
${$os["release"]}
${$os[2]}
(Being zero-indexed, this accesses the value of the third key-value pair in theos
hash)${$osrelease}
(This accesses the value of the third key-value pair in therelease
hash)
In the console, an index can be only simple string literals or decimal integer literals. An index cannot include variables or operations (such as string concatenation or integer arithmetic). These are examples of illegal expression-style interpolation:
${$::os}
{$os[$release]}
${$os[0xff]}
${$os[6/3]}
${$os[$family + $release]}
${$os + $release}
Trusted facts
Trusted facts are considered to be keys of a hashmap called trusted
.
This means that trusted facts must be interpolated using expression-style syntax.
For example, the certname
trusted fact is expressed
as "My name is ${trusted[certname]}"
. Any trusted facts that are
themselves structured facts can have further index expressions to access individual
fields of that trusted fact.
undef
) are not supported.