Ask Your Question
0

Query PuppetDB for 2 facts at once

asked 2015-08-12 14:41:27 -0500

Robert Keating gravatar image

I tried variations of the following, but no luck: ('["or", ["=", "name", "kernelversion"], ["=", "name", "instance_uuid"]]')

thank you for your help!

edit retag flag offensive close merge delete

Comments

Can you post the exact command that you're using as well as the response from the API?

GregLarkin gravatar imageGregLarkin ( 2015-08-12 23:32:47 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-08-13 10:29:18 -0500

Robert Keating gravatar image

updated 2015-08-14 22:02:54 -0500

GregLarkin gravatar image

(edit) Oppps - this is not an 'Answer', its a comment: I get 2 outputs per node. How can I get one output per node?

*Command:*

curl -X GET https://puppetdb01.net:8081/v2/facts \
  --data-urlencode 'query=["or", ["=", "name", "kernelversion"], ["=", "name", "instance_uuid"]]' \
  --tlsv1 \
  --cacert .ca.pem \
  --cert .public.pem \
  --key .private.pem

OUTPUT:

}, {
  "certname" : "pcevstf148g131.dev.net",
  "name" : "instance_uuid",
  "value" : "a5348a51-624c-40b0-9b6b-dfb2dae1b796"
}, {
  "certname" : "pcevstf148g131.dev.net",
  "name" : "kernelversion",
  "value" : "2.6.32"
edit flag offensive delete link more

Comments

Actually its a new question, not even a comment. Either way, the answer is subqueries: https://gist.github.com/kbarber/ab7e5c096ebc79c7bbcb. The example uses PDB 3.0 and the v4 api fyi.

ken gravatar imageken ( 2015-08-17 06:43:02 -0500 )edit
0

answered 2015-08-14 22:09:37 -0500

GregLarkin gravatar image

AFAICT, each fact result will be returned in a separate JSON array, according to http://docs.puppetlabs.com/puppetdb/2...

Do you want the response to look like this?

{
  "certname" : "pcevstf148g131.dev.net",
    { "name" : "instance_uuid", "value" : "a5348a51-624c-40b0-9b6b-dfb2dae1b796" },
    { "name" : "kernelversion", "value" : "2.6.32" }
}

I'm sure that's not valid JSON syntax, but you'll probably get the idea. Unfortunately, it doesn't look like the API can do that, so I guess the best option would be to write a script that consumes the output from the API and rearranges it to the form that you need.

edit flag offensive delete link more

Comments

I don't believe this is entirely true Greg - the API can handle some of it with subqueries, see my comment above. What it can't do is returning that fact data at the same time.

ken gravatar imageken ( 2015-08-17 06:43:37 -0500 )edit

Thank you for the clarification and correct answer above, Ken.

GregLarkin gravatar imageGregLarkin ( 2015-08-18 11:40:39 -0500 )edit

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

Stats

Asked: 2015-08-12 14:41:27 -0500

Seen: 63 times

Last updated: Aug 14 '15