puppetdb - getting a list of specific facts for specific hosts?

4,566 views
Skip to first unread message

Klavs Klavsen

unread,
Sep 2, 2013, 9:26:46 AM9/2/13
to puppet...@googlegroups.com
I'm trying to query puppetdb for a list of hosts maching a certain regex (on hostname) and only returns 2 facts (ipaddress and hostname)

I'm trying to follow:
http://docs.puppetlabs.com/puppetdb/latest/api/query/tutorial.html

and I'm not even quite sure, wether or not, I should use a facts or a nodes, or a resources query ?

I get some of the queries to return just fine.. f.ex. I can query on nodes:
curl -X GET -H 'Accept: application/json' http://localhost:8080/v2/nodes --data-urlencode 'query=["~", ["fact", "hostname"], "webserver"]'

But I can't figure out how I can make that query, return 1 extra fact (ipaddress).. ?

Klavs Klavsen

unread,
Sep 2, 2013, 9:41:11 AM9/2/13
to puppet...@googlegroups.com
I also tried https://github.com/dalen/puppet-puppetdbquery - but that didn't really get me any closer :(

Klavs Klavsen

unread,
Sep 2, 2013, 10:00:17 AM9/2/13
to puppet...@googlegroups.com
This gives me the ipaddress (and hostname).. now to figure out how to filter on hostname regex..

'query=["=", "name", "ipaddress"]'

Ken Barber

unread,
Sep 3, 2013, 2:09:19 PM9/3/13
to Puppet Users
Is it acceptable to do the search based on 'certname'? ie:

curl -G 'http://localhost:8080/v2/facts' --data-urlencode
'query=["and",["~","certname","puppetdb?"],["or",["=","name","ipaddress"],["=","name","hostname"]]]'

ken.
> --
> 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 post to this group, send email to puppet...@googlegroups.com.
> Visit this group at http://groups.google.com/group/puppet-users.
> For more options, visit https://groups.google.com/groups/opt_out.

Klavs Klavsen

unread,
Sep 4, 2013, 8:35:29 AM9/4/13
to puppet...@googlegroups.com
Den tirsdag den 3. september 2013 20.09.19 UTC+2 skrev Ken Barber:
Is it acceptable to do the search based on 'certname'? ie:

curl -G 'http://localhost:8080/v2/facts' --data-urlencode
'query=["and",["~","certname","puppetdb?"],["or",["=","name","ipaddress"],["=","name","hostname"]]]'


 Thank you - that worked beautifully :)

Only "detail" - is that it shows 2 results for each host - one for each fact being retrieved.

robert keating

unread,
Aug 12, 2015, 4:03:49 PM8/12/15
to Puppet Users
Can you help with this query?  I am trying to get 2 facts from all of our puppet clients in PuppetDB.  
I tried variations of the following, but no luck: ('["or", ["=", "name", "kernelversion"], ["=", "name", "instance_uuid"]]')

Thank you!

Ken Barber

unread,
Aug 12, 2015, 4:23:48 PM8/12/15
to Puppet Users
> Can you help with this query? I am trying to get 2 facts from all of our
> puppet clients in PuppetDB.
> I tried variations of the following, but no luck: ('["or", ["=", "name",
> "kernelversion"], ["=", "name", "instance_uuid"]]')

For me this query works. Here is the full curl example in the latest
PDB (I replaced instance_uuid with operatingsystem, since I don't have
that fact and I wanted to show it working with _something_):

# curl -G 'http://localhost:8080/pdb/query/v4/facts' --data-urlencode
'query=["or",["=","name","kernelversion"],["=","name","operatingsystem"]]'
[ {
"certname" : "kb.local",
"environment" : "production",
"name" : "operatingsystem",
"value" : "Darwin"
}, {
"certname" : "kb.local",
"environment" : "production",
"name" : "kernelversion",
"value" : "14.4.0"
} ]%

ken.
Reply all
Reply to author
Forward
0 new messages