PuppetDB Query based on facts

570 views
Skip to first unread message

Mike Sharpton

unread,
Jun 3, 2016, 1:40:19 PM6/3/16
to Puppet Users
Hey all,

I am trying to do what should be a simple thing.  I need to query PuppetDB to gather a list of machines based on arbitrary facta being equal to true and the operatingsystemmajrelease fact being 7.  I have searched around and found a few examples, but can't get them to work properly.  I saw and example from Wyatt on here, but I must be doing something wrong as I can't even get that to run.  I have PuppetDB 3.2.0.

I'm not sure if I should be running my query against this endpoint /pdb/query/v4/facts/, or drill into the facta uri and run a in/and against the operatingsystemmajrelease fact to get what I need.  All I need back is the certname of the machines in which facta is true and operatingsystemmajrelease is 7.  If someone has a quick one liner, it would be appreciated, otherwise I can bust out the data and filter it with Excel.  Thanks,

Mike

Wyatt Alt

unread,
Jun 3, 2016, 2:56:41 PM6/3/16
to puppet...@googlegroups.com
Hey Mike,
I'm thinking you want something like this:

curl -X GET http://localhost:8080/pdb/query/v4/nodes -d 'query=["and", ["=", ["fact", "operatingsystemmajrelease"], 7], ["=", ["fact", "facta"], true]]'

Wyatt



--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/5a1fec0e-1d02-442f-9465-9660a6087a8f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mike Sharpton

unread,
Jun 3, 2016, 3:38:42 PM6/3/16
to Puppet Users
Wyatt,

Thanks for your reply.  I changed out my url and facta to my fact name, nothing is returned except this.

[ ]

To ensure it wasn't my fact that was messing this up, I tried another standard fact is_pe.  The value should be uppercase "False" but this returns a 500 when run that post/GET.

:8080/pdb/query/v4/nodes -d 'query=["and", ["=", ["fact", "operatingsystemmajrelease"], 7], ["=", ["fact", "is_pe"], False]]'

This returns nothing as well.  I have about 350 nodes of this type.

:8080/pdb/query/v4/nodes -d 'query=["and", ["=", ["fact", "operatingsystemmajrelease"], 7], ["=", ["fact", "is_pe"], false]]'

My fact value is lowercase as well, true is the value.  Any ideas?  

Thanks in advance,
Mike

Wyatt Alt

unread,
Jun 3, 2016, 4:31:28 PM6/3/16
to puppet...@googlegroups.com, Mike Sharpton
Hey Mike,

I think operatingsystemmajrelease might be a string instead of an int,
based on https://tickets.puppetlabs.com/browse/FACT-962. You also might
verify that facta is valued with a real boolean instead of a stringified
bool (the reference to casing made me wonder.)

Wyatt

Mike Sharpton

unread,
Jun 3, 2016, 5:37:14 PM6/3/16
to Puppet Users, shar...@gmail.com
Yep, the value of my fact is a string.  I will keep googling around to see what I can find.  Thanks,

Mike

Wyatt Alt

unread,
Jun 3, 2016, 5:43:17 PM6/3/16
to puppet...@googlegroups.com, Mike Sharpton
Mike,

Where I was going with that is you might get results with


curl -X GET http://localhost:8080/pdb/query/v4/nodes -d 'query=["and", ["=", ["fact", "operatingsystemmajrelease"], "7"], ["=", ["fact", "facta"], "true"]]'

or

curl -X GET http://localhost:8080/pdb/query/v4/nodes -d 'query=["and", ["=", ["fact", "operatingsystemmajrelease"], "7"], ["=", ["fact", "facta"], "True"]]'

Let me know if one of those does it.

Wyatt


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.

Mike Sharpton

unread,
Jun 3, 2016, 6:37:59 PM6/3/16
to Puppet Users, shar...@gmail.com
Doh!  Quotes matter, didn't think of it.  That appears to work, I grepped and piped and have my list.  Thanks very much again, you have saved me work twice now.  

Mike

Mike Sharpton

unread,
Jun 3, 2016, 6:40:43 PM6/3/16
to Puppet Users, shar...@gmail.com
I was messing around in psql to see if I could figure out the table structure and just query without the API wrapper, I couldn't before you replied.  Price is right losing horn.
Reply all
Reply to author
Forward
0 new messages