Ansible Tower REST API: Is there any way to get the logs/output of a job?

Viewed 11504

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?

3 Answers

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
Related