forked from linux/documentation
1.1 KiB
1.1 KiB
Puppet API
Puppet provides an API to query the inventory of hosts and their facts. This can be used for debugging purposes, but also to get information about the hosts in a more structured way than just looking at the sysdb.
Following is an example of how to query the inventory using curl (returns about 80MB of json):
curl -G https://puppet.psi.ch/pdb_api/inventory
To get the facts of a specific host, you can do:
curl -G https://puppet.psi.ch/pdb_api/inventory --data-urlencode 'query=["=", "certname", "merlin-c-321.psi.ch"]'
With jq you can filter the output to get only the information you are interested in. For example, to get only the hostnames of all hosts, you can do:
curl -G https://puppet.psi.ch/pdb_api/inventory | jq '.[].certname'
List all machines with a specific package such as yfs-client installed:
curl -G https://puppet.psi.ch/pdb_api/inventory | jq -r '.[] | select(.facts.installed_packages[][0] | startswith("yfs-client")) | .certname '
More details about what is possible with the API can be found here: https://help.puppet.com/pdb/8/topics/query.htm