You can see all the Hiera lookups for class parameters for any node by querying the Catalog API and parsing the output logs for the Hiera lookups.
Version and installation information
PE version: All supported versions
This solution requires that the jq
utility is installed. We cannot provide support for third-party software.
Solution
The debug logs in the response from the Catalog API contain the lookup --explain
results for parameters. Therefore, you can retrieve a compiled catalog for a node with a curl command and filter the output with jq, a lightweight JSON command line processor using a curl
command.
On your primary server, run the following command replacing <NODE>
with the certname of the node you’d like results for:
curl -ksS \
-H "Content-Type: application/json" \
--cert $(/opt/puppetlabs/bin/puppet config print hostcert) \
--key $(/opt/puppetlabs/bin/puppet config print hostprivkey) \
https://localhost:8140/puppet/v4/catalog \
-d \
"{\"certname\": \"<NODE>\",
\"persistence\": {\"facts\": false,
\"catalog\": false},
\"environment\": \"production\",
\"options\": {\"capture_logs\": true,
\"log_level\": \"debug\"}}" | jq -r '.logs[]|.message|select(.|test("Lookup of"))'
This excerpt shows the lookup result for mymodule::test
:
Automatic Parameter Lookup of 'mymodule::test'
Searching for "lookup_options"
Global Data Provider (hiera configuration version 5)
Using configuration "/etc/puppetlabs/puppet/hiera.yaml"
Hierarchy entry "Classifier Configuration Data"
No such key: "lookup_options"
Environment Data Provider (hiera configuration version 5)
Using configuration "/etc/puppetlabs/code/environments/production/hiera.yaml"
Original path: "nodes/%{trusted.certname}.yaml"
No such key: "lookup_options"
Original path: "%{domain}.yaml"
Path not found
Path "/etc/puppetlabs/code/environments/production/data/common.yaml"
Original path: "common.yaml"
No such key: "lookup_options"
Module "mymodule" Data Provider (hiera configuration version 5)
Using configuration "/etc/puppetlabs/code/environments/production/site-modules/mymodule/hiera.yaml"
Merge strategy hash
Hierarchy entry "osfamily/major release"
Merge strategy hash
Path "/etc/puppetlabs/code/environments/production/site-modules/mymodule/data/os/CentOS/7.yaml"
Original path: "os/%{facts.os.name}/%{facts.os.release.major}.yaml"
Path not found
Path "/etc/puppetlabs/code/environments/production/site-modules/mymodule/data/os/RedHat/7.yaml"
Original path: "os/%{facts.os.family}/%{facts.os.release.major}.yaml"
Path not found
Original path: "os/%{facts.os.family}/%{facts.kernelrelease}.yaml"
Path not found
Hierarchy entry "osfamily"
Merge strategy hash
Path "/etc/puppetlabs/code/environments/production/site-modules/mymodule/data/os/CentOS.yaml"
Original path: "os/%{facts.os.name}.yaml"
Path not found
Path "/etc/puppetlabs/code/environments/production/site-modules/mymodule/data/os/RedHat.yaml"
Original path: "os/%{facts.os.family}.yaml"
Path not found
Hierarchy entry "common"
Path "/etc/puppetlabs/code/environments/production/site-modules/mymodule/data/common.yaml"
Original path: "common.yaml"
No such key: "lookup_options"
Searching for "mymodule::test"
Global Data Provider (hiera configuration version 5)
Using configuration "/etc/puppetlabs/puppet/hiera.yaml"
Hierarchy entry "Classifier Configuration Data"
No such key: "mymodule::test"
Environment Data Provider (hiera configuration version 5)
Using configuration "/etc/puppetlabs/code/environments/production/hiera.yaml"
Hierarchy entry "Yaml backend"
Path "/etc/puppetlabs/code/environments/production/data/nodes/<NODE>"
Original path: "nodes/%{trusted.certname}.yaml"
Found key: "mymodule::test" value: "foo"
How can we improve this article?
0 comments
Please sign in to leave a comment.
Related articles