The puppet lookup command
The puppet
lookup
command is the command line interface (CLI) for Puppet's lookup function.
The puppet lookup
command lets you do Hiera lookups from the command line.
You must run it on a node that has a copy of your Hiera
data. You can log into a Puppet Server node and run
puppet lookup
with
sudo
.
The most common version of this command is:
puppet lookup <KEY> --node <NAME> --environment <ENV> --explain
The puppet lookup
command searches your Hiera data and returns a value for
the requested lookup key, so you can test and explore your data. It replaces the hiera
command. Hiera relies on a node's facts to locate the relevant
data sources. By default, puppet
lookup
uses facts from the node you run the command on, but you can get
data for any other node with the --node NAME
option. If possible, the lookup command uses the requested
node's real stored facts from PuppetDB. If PuppetDB is not configured or you want to provide other
fact values, pass facts from a JSON or YAML file with the --facts FILE
option.
puppet lookup
command replaces the hiera
command.Examples
To look up key_name
using the Puppet Server node’s facts:
$ puppet lookup key_nameTo look up
key_name
with agent.local
's
facts:$ puppet lookup --node agent.local key_nameTo get the first value found for
key_name_one
and
key_name_two
with agent.local
's facts while
merging values and knocking out the prefix 'example' while
merging:puppet lookup --node agent.local --merge deep --knock-out-prefix example key_name_one key_name_twoTo lookup
key_name
with agent.local
's facts, and
return a default value of 0
if nothing is
found:puppet lookup --node agent.local --default 0 key_nameTo see an explanation of how the value for
key_name
is
found, using agent.local
facts:puppet lookup --node agent.local --explain key_name
Options
The puppet lookup
command has the following command options:
--help
: Print a usage message.--explain
: Explain the details of how the lookup was performed and where the final value came from, or the reason no value was found. Useful when debugging Hiera data. If--explain
isn't specified, lookup exits with 0 if a value was found and 1 if not. With--explain
, lookup always exits with 0 unless there is a major error. You can provide multiple lookup keys to this command, but it only returns a value for the first found key, omitting the rest.--node <NODE-NAME>
: Specify which node to look up data for; defaults to the node where the command is run. The purpose of Hiera is to provide different values for different nodes; use specific node facts to explore your data. If the node where you're running this command is configured to talk to PuppetDB, the command uses the requested node's most recent facts. Otherwise, override facts with the '--facts' option.--facts <FILE>
: Specify a JSON or YAML file that contains key-value mappings to override the facts for this lookup. Any facts not specified in this file maintain their original value.--environment <ENV>
: Specify an environment. Different environments can have different Hiera data.--merge first/unique/hash/deep
: Specify the merge behavior, overriding any merge behavior from the data'slookup_options
.--knock-out-prefix <PREFIX-STRING>
: Used with 'deep' merge. Specifies a prefix to indicate a value should be removed from the final result.--sort-merged-arrays
: Used with 'deep' merge. When this flag is used, all merged arrays are sorted.--merge-hash-arrays
: Used with the 'deep' merge strategy. When this flag is used, hashes within arrays are deep-merged with their counterparts by position.--explain-options
: Explain whether alookup_options
hash affects this lookup, and how that hash was assembled. (lookup_options
is how Hiera configures merge behavior in data.)--default <VALUE>
: A value to return if Hiera can't find a value in data. Useful for emulating a call to the `lookup function that includes a default.--type <TYPESTRING>
: Assert that the value has the specified type. Useful for emulating a call to thelookup
function that includes a data type.--compile
: Perform a full catalog compilation prior to the lookup. If your hierarchy and data only use the$facts
,$trusted
, and$server_facts
variables, you don't need this option. If your Hiera configuration uses arbitrary variables set by a Puppet manifest, you need this to get accurate data. Thelookup
command doesn't cause catalog compilation unless this flag is given.--render-as s/json/yaml/binary/msgpack
: Specify the output format of the results;s
means plain text. The default when producing a value isyaml
and the default when producing an explanation iss
.