Ansible AWX / Ansible Tower supports RESTfull API calls. It provides greater flexibility that you no need to be in Ansible Tower/AWX console to start the template or read the ansible job results. You could post the API from anywhere. It could be a web portal or from your laptop using POSTMAN/SoapUI. This article will demonstrate how to POST job using API and how to read the job result using the GET method.
We will also walk through how to pass the user defined variable when you POST API to ansible template.
1. Here is the ansible template and template ID. If you keep the mouse near to that template, you can see the template id in the bottom of the screen.

2. How to navigate to AWX/ Ansible Tower API? Please refer the following screenshot.

3. You could access the job template REST API like below.

4. Download POSTMAN or SoapUI . Here, I will use Postman for the demo.
5. Open Postman and create a new tab like below.

- To launch the ansible template, select the POST method.
- In the Authorization tab, feed the basic authentication for ansible Tower / AWX
6. If the playbooks require an extra variable, you can pass it in the body of the API calls in JSON format.

Here ,
- Ansible Playbook variable – FS_MOUNTPOINT
- Value for the variable is – “/var” .
Here, we could pass as many as variable if needed by the playbook/AWX/Tower template survey.
7. Click on send to POST the API call. It should get the status code of 201 for the successfull post. Note down the job ID for validation.

8. Login to AWX / Ansible Tower to check the job status.

We have successfully launched the Ansible Tower job template without accessing the Ansible Tower /AWX console. REST API allows to POST from anywhere and get the desired results.
Hope this article is informative to you. Share it! Comment it !! Be Sociable !!!
The post Ansible Tower / AWX – Trigger Ansible Job using REST API appeared first on UnixArena.