Access hash and array elements using a key.subkey notation
Access hash and array members in Hiera using a key.subkey
notation.
You can access hash and array elements when doing the following things:
Interpolating variables into
hiera.yaml
or a data file. Many of the most commonly used variables, for examplefacts
andtrusted
, are deeply nested data structures.Using the
lookup
function or thepuppet lookup
command. If the value oflookup('some_key')
is a hash or array, look up a single member of it by usinglookup('some_key.subkey')
.Using interpolation functions that do Hiera lookups, for example
lookup
andalias
.
To access a single member of an array or hash:
- Use the name of the value followed by a period
(
.
) and a subkey.-
If the value is an array, the subkey must be an integer, for example:
users.0
returns the first entry in theusers
array. -
If the value is a hash, the subkey must be the name of a key in that hash, for example,
facts.os
. -
To access values in nested data structures, you can chain subkeys together. For example, because the value of
facts.system_uptime
is a hash, you can access its hours key withfacts.system_uptime.hours
.
Example:
To look up the value of
home
in this data:accounts::users: ubuntu: home: '/var/local/home/ubuntu'
You would use the following
lookup
command:lookup('accounts::users.ubuntu.home')
-