Guidelines

This site is for tech Q&A. Please keep your posts focused on the subject at hand.

Ask one question at a time. Don't conflate multiple problems into a single question.

Make sure to include all relevant information in your posts. Try to avoid linking to external sites.

Links to documentation are fine, but in addition you should also quote the relevant parts in your posts.

0 votes
16 views
16 views

We're managing our servers from a central Puppet server. I need to get the value of a custom fact (specifying the datacenter/location of each server) for all of our managed servers.

I know that I could use pdsh to query the fact locally on each server, but there should be a way to get the information on the Puppet server (since the information is already being stored in PuppetDB).

in General by (245) 7

Your answer

Preview

Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
By submitting this post you agree to our Terms & Conditions.
To avoid this verification in future, please log in or register.

1 Answer

0 votes
 
Best answer

PuppetDB has a REST API from which you can query facts like this:

curl -Gs "http://localhost:8080/pdb/query/v4/facts/YOUR_FACT"

Replace YOUR_FACT with the actual name of your custom fact (or any other fact).

The output is a JSON document. To get a list mapping the FQDN of the server to the value of the fact you can use jq like this:

curl -Gs "http://localhost:8080/pdb/query/v4/facts/YOUR_FACT" |
  jq -r '.[]|[.certname, .value]|@tsv'

That will produce output like

bar2342.example.org	abc
baz13.example.org	def
foo.example.org	ghi
...

Use column to get the columns aligned properly:

curl -Gs "http://localhost:8080/pdb/query/v4/facts/YOUR_FACT" |
  jq -r '.[]|[.certname, .value]|@tsv' |
  column -ts $'\t'

Output:

bar2342.example.org  abc
baz13.example.org    def
foo.example.org      ghi
...
by (245) 7
...