You might need to include or exclude a large number of nodes in a Puppet Query Language (PQL) query due to multiple OS with different version numbers. If so, choosing the right query operator can reduce query execution time and improve performance.
Version and installation information
PE version: All supported
Solution
Use the IN
operator instead of the OR
operator when you have a large number of nodes to include or exclude. When running a PQL query on a smaller number of nodes, it doesn’t take as much time to process the query, so the operator that you choose doesn’t affect query time as much.
Here’s an example of how to improve a query by changing OR
to IN
:
This example using OR
is not efficient:
puppet query 'inventory[certname] {
! (
certname = "puppet00.puppet.com" or
certname = "puppet01.puppet.com" or
certname = "puppet02.puppet.com" or
certname = "puppet03.puppet.com" or
certname = "puppet04.puppet.com" or
certname = "puppet05.puppet.com" or
certname = "puppet06.puppet.com" or
certname = "puppet07.puppet.com" or
certname = "puppet08.puppet.com" or
)}’
Here’s a more efficient version of the query using IN
:
puppet query 'inventory[certname] {
! (
certname in [
"puppet00.puppet.com",
"puppet01.puppet.com",
"puppet02.puppet.com",
"puppet03.puppet.com",
"puppet04.puppet.com",
"puppet05.puppet.com",
"puppet06.puppet.com",
"puppet07.puppet.com",
"puppet08.puppet.com",
]
)}’
Learn more about PQL by reading Learn to use Puppet Query Language (PQL).
How can we improve this article?
0 comments
Please sign in to leave a comment.
Related articles