Ask Your Question

How to query puppet db under /facts and receive only active instances

asked 2016-08-11 09:31:06 -0600

subzero112233 gravatar image


When querying puppet db with a query like this: "curl -X GET http://puppetserver:8080/pdb/query/v4... --data-urlencode 'query=[\"extract\", \"value\",[\"and\",[\"=\",\"certname\", \"${machine}\"]]]'"

I receive all instances with the relevant ec2_project tag. I want to omit the inactive instances and receive only running ones.

How can I get it done?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-10-04 09:53:02 -0600

Dziki_Jam gravatar image

updated 2016-10-05 01:59:06 -0600

curl -X GET http://localhost:8080/pdb/query/v4/nodes --data-urlencode "query=[\">\", \"facts_timestamp\", \"$(date -d '-1 day' -Isec)\"]"

This query will output list of nodes that was active withing 1 day. You can save it to a variable and parse certificates with bash, for example. The query gets all the information from puppetdb, so you need to replace http://localhost:8080 with your puppetdb address.

Example output:

"deactivated" : null,
  "latest_report_hash" : "299b9ba73597835b0218b068267053e065224a7a",
  "facts_environment" : "production",
  "report_environment" : "production",
  "catalog_environment" : "production",
  "facts_timestamp" : "2016-10-05T06:21:45.721Z",
  "expired" : null,
  "report_timestamp" : "2016-10-05T06:23:56.316Z",
 "certname" : "node1.examplom",
  "catalog_timestamp" : "2016-10-05T06:21:47.500Z",
  "latest_report_status" : "changed"
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-08-11 09:31:06 -0600

Seen: 114 times

Last updated: Oct 05 '16