Hiera

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.yaml or a data file. Many of the most commonly used variables, for example facts and trusted, are deeply nested data structures.
  • Using the lookup function or the puppet lookup command. If the value of lookup('some_key') is a hash or array, look up a single member of it by using lookup('some_key.subkey').
  • Using interpolation functions that do Hiera lookups, for example lookup and alias.

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 the users 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 with facts.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')

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *