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