Run Puppet on a PQL query
An orchestrator job can target a set of nodes based on a PQL query. This is useful when you want to target a variable set of nodes that meet specific conditions, such as a particular operating system. When you supply a PQL query, the orchestrator runs the job on a list of nodes generated by the PQL query.
Make sure you have access to the nodes you want to target.
Make sure you have the permissions necessary to run jobs and PQL queries.
- Log into your primary server or the client tools workstation.
- Run one of the following commands:
- To supply the PQL query in the
command:
puppet job run --query '<QUERY>'
For example:
puppet job run --query 'nodes[certname] { facts {name = "operatingsystem" and value = "Debian" }}'
- To supply the query in a text
file:
puppet job run --query @<PATH_TO_.txt_FILE>
You can append additional options, such as--noop
, after the query or filepath. To learn about options you can supply to this command, refer to puppet job run command options.The following table shows some examples of PQL queries you might use for particular node targets.
Target PQL query A single node by certname 'nodes { certname = "mynode" }'
All nodes with web in their certname 'nodes { certname ~ "web" }'
All CentOS nodes 'inventory { facts.os.name = "CentOS" }'
All CentOS nodes with httpd managed 'inventory { facts.operatingsystem = "CentOS" and resources { type = "Service" and title = "httpd" } }'
All nodes with failed reports 'reports { latest_report? = true and status = "failed" }'
All nodes matching the environment of the last received catalog 'nodes { catalog_environment = "production" }'
Make sure to wrap the entire query in single quotes and use double quotes inside the query. To shorten the command, you can use-q
in place of--query
. - To supply the PQL query in the
command:
When you execute the puppet job run
command, the orchestrator generates
a job ID for the job, shows you a list of nodes targeted by the job, and proceeds to run
Puppet on the targeted nodes in the appropriate order.
Puppet compiles a new catalog for all nodes targeted
by the job.
To view the job status, run: puppet job show <JOB_ID>
To view a list of the 50 most-recent running and completed jobs, run: puppet job
show