Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 201
Jeevitha G Avatar asked Oct 06 '17 18:10

Jeevitha G


People also ask

Does Ansible support REST API?

Some user operations may not be supported in the modules, however you can use the Ansible URI module to make direct calls to any API including the PowerMax REST API which will ensure that even your corner case can be supported in an Ansible playbook.

How do I monitor Ansible Tower?

Validating Ansible Tower metricsTo generate the token, access the Ansible Tower console and click on your username that appears at the top of the page. From there, click on “Tokens” and then on the + sign. A new window pops up where you can define the specifics of the token and finally create it, see the image below.

Where are the Ansible logs?

ansible. cfg (in the home directory) /etc/ansible/ansible. cfg.


1 Answers

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
like image 160
aj-devops-wi Avatar answered Nov 15 '22 10:11

aj-devops-wi