简体   繁体   中英

How can I check if a playbook is being used by any job template?

We have an organization with several hundred job templates.

I essentially want to do some housekeeping and identify any unused playbooks in my repository.

Is there a way to get details about each job template (including playbook) so that I can grep for a specific playbook?

Is there a way to get details about each job template (including playbook) so that I can grep for a specific playbook?

The short answers is: yes, of course. The long answer is: someone has to create such task. To do so, one may getting familiar with the Ansible Tower REST API , in detail Job Templates - List Job Templates .

In example, a call to List Job Templates

curl --silent --user ${ACCOUNT}:${PASSWORD} https://${TOWER_URL}/api/v2/job_templates/ --write-out "\n%{http_code}\n" | jq .

would result into an output (example) of

{
  "count": 29,
  "next": "/api/v2/job_templates/?page=2",
  "previous": null,
  "results": [
    {
      ...
    }
  ]
}
200

results will contain the list of all Job Templates. For further processing one may look for the values of the key playbook in --raw-output only.

curl --silent --user ${ACCOUNT}:${PASSWORD} https://${TOWER_URL}/api/v2/job_templates/ | jq --raw-output '.results[] | .playbook'

One can then just grep over the output.

Further Q&A

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM