Forked from tuxfight3r/gist:9056eb0862fdf2e8b8755b3c6ce40af1
Created
November 1, 2021 02:20
-
-
Save tutelacooldouce/9020bf0798cc1ccb482715529c9eb902 to your computer and use it in GitHub Desktop.
Puppetdb query examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| curl -s -X GET http://localhost:8080/pdb/query/v4/facts --data-urlencode query@test --data-urlencode 'pretty=true' | |
| curl -X POST http://localhost:8080/pdb/query/v4/facts \ | |
| -H 'Content-Type:application/json' \ | |
| -d '{"query":["and",["=","certname","FQDN"],["=","name","ipaddress"]]}' | |
| content of file test : | |
| ["and",["=","certname","FQDN"],["or",["=","name","ipaddress"]]] | |
| ["and",["=","certname","FQDN"],["=","name","ipaddress"]] | |
| ["and", | |
| ["=", "name", "bios_version"], | |
| ["in", "certname", | |
| ["extract", "certname", ["select_facts", | |
| ["and", | |
| ["=", ["fact", "manufacturer"], "Dell Inc."], | |
| ["=", ["fact", "productname"], "PowerEdge R620"]]]]]] | |
| To select all DELL model | |
| ["and", | |
| ["=", "name", "bios_version"], | |
| ["in", "certname", | |
| ["extract", "certname", ["select_facts", ["=", ["fact", "manufacturer"], "Dell Inc."] ]]]] | |
| To get hostname in fact : | |
| ["and", | |
| ["=", "name", "hostname"], | |
| ["in", "certname", | |
| ["extract", "certname", ["select_facts", ["=", ["fact", "hostname"], "myhostname"] ]]]] | |
| Request 2 facts : | |
| [ "or", | |
| ["=", "name", "ipaddress"], | |
| ["=", "name", "operatingsystem"] | |
| ] | |
| Query with mutliple fact with OR : | |
| ["and", | |
| ["=", "name", "hostname"], | |
| ["in", "certname", | |
| ["extract", "certname", ["select_facts", | |
| ["or", | |
| ["=", ["fact", "s_role"], "role1"], | |
| ["=", ["fact", "s_role"], "role2"], | |
| ["=", ["fact", "s_role"], "role3"]]]]]] | |
| Query with mutliple fact with OR and AND: | |
| ["and", | |
| ["=", "name", "hostname"], | |
| ["in", "certname", | |
| ["extract", "certname", ["select_facts", | |
| ["and", | |
| ["=", ["fact", "s_datacenter"], "mydc"], | |
| ["or", | |
| ["=", ["fact", "s_role"], "role1"], | |
| ["=", ["fact", "s_role"], "role2"], | |
| ["=", ["fact", "s_role"], "role3"]]]]]]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment