Puppet PQL Queries

PQL syntax can be a bit tricky/ugly. It took me some time to figure this out so I thought sharing it isn’t a bad idea.

Get all nodes with a specific class in their last catalog

puppet query 'nodes[certname] {resources {type = "class" and title = "CapitalizedClassname"}}'

This gives us a list of all nodes that have have a class, for example Apache, in their catalog. Maybe want to have a list of all nodes that use a specific module (that could be Apache::Vhosts but not Apache):

puppet query 'nodes[certname] {resources {type = "class" and title ~ "CapitalizedClassname"}}'

The query can be combined with more matchers, for example on the certificate name:

puppet query 'nodes[certname] {certname ~ "^bla-" and resources {type = "class" and title = "CapitalizedClassname"}}'
This entry was posted in General, Linux, Puppet, Short Tips. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.