Hiera is a Puppet subsystem for fetching fetching facts.
Lookup
The puppet lookup command
The puppet lookup command is the command line interface for Puppet’s lookup function.
This function let’s you do Hiera lookups from the command line. You must run it on node that has a copy of your Hiera data (Pippet Server node with sudo).
puppet lookup <KEY> --node <NAME> --environment <ENV> --explain
Examples
$ puppet lookup key_name
$ puppet lookup --node agent.local key_name
$ puppet lookup --node agent.local --merge deep --knock-out-prefix example key_name_one key_name_two
$ puppet lookup --node agent.local --default 0 key_name
$ puppet lookup --node agent.local --explain key_name
Access hash and array elements using 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 lookup the value of home in this data:
accounts::users:
ubuntu:
home: '/var/local/home/ubuntu'
lookup('accounts::users.ubuntu.home')