Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tutelacooldouce/9020bf0798cc1ccb482715529c9eb902 to your computer and use it in GitHub Desktop.
Save tutelacooldouce/9020bf0798cc1ccb482715529c9eb902 to your computer and use it in GitHub Desktop.
Puppetdb query examples
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