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.yamlor a data file. Many of the most commonly used variables, for examplefactsandtrusted, are deeply nested data structures.Using the
lookupfunction or thepuppet lookupcommand. 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
lookupandalias.
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.0returns the first entry in theusersarray. -
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_uptimeis a hash, you can access its hours key withfacts.system_uptime.hours.
Example:
To look up the value of
homein this data:accounts::users: ubuntu: home: '/var/local/home/ubuntu'You would use the following
lookupcommand:lookup('accounts::users.ubuntu.home') -