forked from linux/documentation
33 lines
1.1 KiB
Markdown
33 lines
1.1 KiB
Markdown
# 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):
|
|
|
|
```bash
|
|
curl -G https://puppet.psi.ch/pdb_api/inventory
|
|
```
|
|
|
|
To get the facts of a specific host, you can do:
|
|
|
|
```bash
|
|
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:
|
|
|
|
```bash
|
|
curl -G https://puppet.psi.ch/pdb_api/inventory | jq '.[].certname'
|
|
```
|
|
|
|
List all machines with a specific package such as `yfs-client` installed:
|
|
|
|
```bash
|
|
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
|
|
|