5

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 /jobs/{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 call for the same?

U880D
  • 8,601
  • 6
  • 24
  • 40
Jeevitha G
  • 1,194
  • 3
  • 13
  • 20

3 Answers3

4

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
2

You can do this via their restful call. To get the job number use a GET against https://yourtowerinstance/api/v2/job_templates/ this will return your templates, and their IDs

To get the output in real time I use this powershell code

    $stdouturl = "https://yourtowerinstance/api/v2/jobs/$($templateResult.id)/stdout/?format=txt"

$resultstd = Invoke-Restmethod -uri $stdouturl -Method 'Get' -Headers $authHeader
while ($resultstd -notmatch 'PLAY RECAP') {
    $resultstd = Invoke-Restmethod -uri $stdouturl -Method 'Get' -Headers $authHeader
    start-sleep -s 5
}
$resultstd
Nathan Julsrud
  • 181
  • 1
  • 3
0

Once you launch a template you get the job-id in response but I don't think there is a API to get the output of the job. However from the dashboard under jobs section you can download the individual job output.

TT.
  • 15,774
  • 6
  • 47
  • 88
RaghuCK
  • 105
  • 3
  • 12