• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

UnixArena

  • Home
  • kubernetes
  • DevOps
    • Terraform
    • Jenkins
    • Docker
    • Openshift
      • OKD
    • Ansible engine
    • Ansible Tower
      • AWX
    • Puppet
  • Cloud
    • Azure
    • AWS
    • Openstack
    • Docker
  • VMware
    • vCloud Director
    • VMware-Guests
    • Vcenter Appliance 5.5
    • vC OPS
    • VMware SDDC
    • VMware vSphere 5.x
      • vSphere Network
      • vSphere DS
      • vShield Suite
    • VMware vSphere 6.0
    • VSAN
    • VMware Free Tools
  • Backup
    • Vembu BDR
    • Veeam
    • Nakivo
    • Azure Backup
    • Altaro VMBackup
    • Spinbackup
  • Tutorials
    • Openstack Tutorial
    • Openstack Beginner’s Guide
    • VXVM-Training
    • ZFS-Tutorials
    • NetApp cDot
    • LVM
    • Cisco UCS
    • LDOM
    • Oracle VM for x86
  • Linux
    • How to Articles
    • Q&A
    • Networking
    • RHEL7
  • DevOps Instructor-led Training
  • Contact

Ansible Tower / AWX – Trigger Ansible Job using REST API

March 21, 2019 By Cloud_Devops 6 Comments

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 !!!

Filed Under: Ansible engine, Ansible Tower, AWX, Configuration Management, DevOps Tagged With: Ansible, Ansible Tower, AWX

Reader Interactions

Comments

  1. Lost1 says

    December 12, 2020 at 9:14 pm

    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 ?

    Reply
  2. Sam says

    June 28, 2020 at 10:51 am

    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

    Reply
  3. Bhanu says

    May 18, 2020 at 9:09 pm

    Hello,

    I am looking for option for changing {{ask_variables_on_launch”: false}} to true. So that I can pass extra_vars options

    Reply
  4. MOHAMMED GAFFAR says

    December 13, 2019 at 11:25 am

    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

    Reply
  5. Mark says

    June 8, 2019 at 7:45 pm

    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

    Reply
    • Lingeswaran R says

      June 10, 2019 at 6:25 pm

      Mark,
      Thank for your valuable feedback. Yet to explore about AWS API using OAuth2.

      Thank you
      Lingesh

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Follow UnixArena

  • Facebook
  • LinkedIn
  • Twitter

Copyright © 2025 · UnixArena ·

Go to mobile version