Quantcast
Channel: Lingesh, Author at UnixArena
Viewing all articles
Browse latest Browse all 369

Ansible Tower / AWX – Trigger Ansible Job using REST API

$
0
0

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.

Job Template ID - Ansible
Job Template ID – Ansible

 

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

Ansible Tower - AWX REST API v2
Ansible Tower – AWX REST API v2

 

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

Ansible Job Template - REST API
Ansible Job Template – REST API

 

4. Download POSTMAN or SoapUI . Here, I will use Postman for the demo.

 

5. Open Postman and create a new tab like below.

POSTMAN - Ansible Template job URL
POSTMAN – Ansible Template job URL
  • 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.

Passing Extra Variable - Ansible Template - POST API
Passing Extra Variable – Ansible Template – POST API

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.

POST API - Ansible
POST API – Ansible

 

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

Ansible Job - Triggered using API
Ansible Job – Triggered using API

 

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.


Viewing all articles
Browse latest Browse all 369

Trending Articles