Is there any way to get the logs/ output of a job using Ansible Tower Rest API

Jeevitha G picture Jeevitha G · Oct 6, 2017 · Viewed 7.7k times · Source

I have a ansible job started by Another Process. Now I need to check the status of the current running job in Ansible Tower . I am able to track the status whether it is running/success/failed/canceled with the job Id ] using Rest API . But I would also need the information of the console logs/ouputs of the task for processing as well . Is there any direct API for the same ?

Answer

aj-devops-wi picture aj-devops-wi · Apr 13, 2018

You can access the job log via a link similar to:

https://tower.yourcompany.com/api/v1/jobs/12345/stdout?format=txt_download

Your curl command would be similar to: curl -O -k -J -L -u ${username):${password} https://tower.company.com/api/v1/jobs/${jobnumber}/stdout?format=txt_download

obviously replacing ${username}, ${password}, and ${jobnumber} with your own values

The curl flags used:

  • -O : output the filename that is actually downloaded
  • -k : insecure SSL (don't require trusted CAs)
  • -J : content header for file download https://curl.haxx.se/docs/manpage.html#-J
  • -L : follow redirects
  • -u : username and password