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 !!!
Lost1 says
Can you use the API of AWX to trigger a job inside a plabook that is running in AWX ?
For example : first playbooks runs a loop on some inputs, and triggers another AWX jobs for each elements ?
Sam says
Hello!
Thanks for the great article.
I have a question, how can I pass the host ID in the request?
I need the request to work only on a specific server
Bhanu says
Hello,
I am looking for option for changing {{ask_variables_on_launch”: false}} to true. So that I can pass extra_vars options
MOHAMMED GAFFAR says
Hi ,
I tried calling AWX server with REST API http://awx_server_ip/api/v2/hosts/
Got JSON output. Filtered list of hosts added in AWX inventory. This filtering task, I need to write in AWX Django code. Please guide me how to do the same.
Thanks,
Gaffar
Mark says
Hello really good stuff you wrote here !!! Saved me a lot of time 🙂 Would you know by chance how to configure AWS API call using the OAuth2 – ?
Thanks
Mark
Lingeswaran R says
Mark,
Thank for your valuable feedback. Yet to explore about AWS API using OAuth2.
Thank you
Lingesh