1

I am creating a job template in Ansible Tower and then launching it using REST API. Now I need to check the status(PENDING, RUNNING, FAILED, SUCCESSFUL, CANCELLED) of the current running job in Ansible Tower with the job id.

I was trying to run the curl GET requests along with jq to parse json output, but there are so many fields with different job events as well the previous job records in the GET output which I couldn't figure out the right way to filter my expected output(current job status).

/api/v2/jobs/{jobId}/
/api/v2/jobs/{jobId}/job_events/
/api/v2/jobs/{jobId}/job_host_sumamries/
/api/v2/jobs/{jobId}/activity_stream/

Is there a way to get job status of the particular job with job id.

vivek
  • 11
  • 1
  • 4
  • 2
    What does not meet your expectation with `/api/v2/jobs/{jobId}/` ? This is supposed to return several fields from which you can inspect the status (`changed`, `dark`, `failures`, `ok`, `processed`, `skipped`, `failed`, `ignored`, `rescued`...) => https://docs.ansible.com/ansible-tower/latest/html/towerapi/api_ref.html#/Jobs – Zeitounator Oct 25 '21 at 14:47
  • I have redirected the curl o/p of /api/v2/jobs/{jobId}/ to json file and tried to parse it with jq to get the job status. I am getting three entries for a job output now. so is it displaying the status of each task within the playbook and not the actual job status? I used the command " cat file.json | jq '. | select(.id == {Job_id}) | .status' and the output is "successful" \n "successful" \n "successful" – vivek Oct 25 '21 at 15:45

1 Answers1

0

I think @zeinatour has the best solution... In this url :

<your tower server>/api/v2/jobs/<jobid>

Look for those entries :

"status": "successful",
"failed": false,

If not, to get to know a job status would be to poke in a loop :

<your tower server>/api/v2/jobs/<jobid>/stdout/

and look for the PLAY RECAP and parse it :

PLAY RECAP *********************************************************************
<host>               : ok=4    changed=1    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   

After the parsing if there is only ok values and no failed I think you can conclude that there is a success ! ;)