Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

Ansible: How to Work with Ansible Tower REST API (with Example)

Absolutely! Ansible Tower (now called Controller in AAP) has a robust, well-documented REST API. You can use it to automate everything you do via the web UIโ€”launch jobs, manage inventories, users, credentials, and more.
Below is a practical, step-by-step guide (with examples!) to help you get started.


How to Work with Ansible Tower REST API (with Example)


1. Understanding the Ansible Tower API

  • Type: RESTful, JSON-based API.
  • Docs: Interactive Swagger/OpenAPI docs usually at:
    https://<tower-server>/api/
    (log in and try it!)
  • Authentication:
    • Basic Auth (username/password or Personal Access Token)
    • OAuth2 (for advanced use cases)

2. API Authentication

  • Basic Auth:
    Every request uses HTTP basic authentication.
    Example: user:password or Personal Access Token as username (no password needed).
  • Getting a Token:
    In Tower UI:
    User โ†’ Tokens โ†’ Create Token
    (Recommended: use tokens for automation!)

3. Making a Simple API Request

Letโ€™s say your Tower UI is at https://13.233.139.133/.

List all Job Templates (curl):

curl -k -u 'admin:yourpassword' https://13.233.139.133/api/v2/job_templates/
Code language: JavaScript (javascript)
  • -k: Allow insecure (self-signed) SSL
  • -u: Basic auth, 'user:password'
  • The response is JSON

Using a Personal Access Token (PAT):

curl -k -H "Authorization: Bearer <your_token>" https://13.233.139.133/api/v2/job_templates/
Code language: JavaScript (javascript)

4. Example: Launch a Job Template via API

Suppose you have a job template with ID 7.

API URL:
POST /api/v2/job_templates/7/launch/

Example (with token):

curl -k -H "Authorization: Bearer <your_token>" \
     -X POST https://13.233.139.133/api/v2/job_templates/7/launch/
Code language: JavaScript (javascript)
  • The response includes the job ID (e.g., "id": 81).

5. Check Job Status

Suppose your launched job returned "id": 81.

curl -k -H "Authorization: Bearer <your_token>" \
     https://13.233.139.133/api/v2/jobs/81/
Code language: JavaScript (javascript)
  • Look for "status": "successful" (other states: “pending”, “running”, “failed”).

6. See Job Output (Standard Out)

curl -k -H "Authorization: Bearer <your_token>" \
     https://13.233.139.133/api/v2/jobs/81/stdout/?format=txt
Code language: JavaScript (javascript)
  • Add ?format=txt or ?format=html as needed.

7. Example: Create an Inventory via API

curl -k -H "Authorization: Bearer <your_token>" \
     -H "Content-Type: application/json" \
     -d '{"name":"TestInventory","organization":1}' \
     -X POST https://13.233.139.133/api/v2/inventories/
Code language: JavaScript (javascript)
  • Replace organization: 1 with your organizationโ€™s ID (list orgs via /api/v2/organizations/).

8. Useful Endpoints

API EndpointDescription
/api/v2/API root & docs
/api/v2/job_templates/List/create job templates
/api/v2/job_templates/<id>/launch/Launch a job template
/api/v2/jobs/<id>/Check job status/details
/api/v2/jobs/<id>/stdout/Get job standard output
/api/v2/inventories/List/create inventories
/api/v2/hosts/List/create hosts
/api/v2/credentials/List/create credentials
/api/v2/users/List/create users

9. Example Python Script (requests library)

Hereโ€™s a simple Python snippet to list all job templates:

import requests

api_url = "https://13.233.139.133/api/v2/job_templates/"
token = "<your_token>"  # Or use user/pass in auth param

headers = {
    "Authorization": f"Bearer {token}",
    "Content-Type": "application/json"
}

response = requests.get(api_url, headers=headers, verify=False)
for jt in response.json()['results']:
    print(f"ID: {jt['id']}, Name: {jt['name']}")
Code language: PHP (php)

(use verify=False for self-signed SSL)


10. Finding More API Endpoints and Docs

  • Visit: https://<tower-server>/api/ in your browser
  • Try out requests in Swagger UI

Summary Table

ActionHTTP MethodAPI URLNotes
List job templatesGET/api/v2/job_templates/
Launch a job templatePOST/api/v2/job_templates/<id>/launch/Needs job template ID
Check job statusGET/api/v2/jobs/<id>/
Get job outputGET/api/v2/jobs/<id>/stdout/?format=txt
Create inventoryPOST/api/v2/inventories/JSON body needed

Tips and Best Practices

  • Use Personal Access Tokens for CI/CD or scripts (not passwords).
  • Always use HTTPS for security.
  • Use the /api/ browser docs for full details and live โ€œtry it nowโ€ features.
  • Automate with Python (requests), Bash (curl), or your favorite language.
  • Respect rate limits and error messagesโ€”read the "detail" field in API responses for helpful info.
  • For bulk/complex changes, look at tower-cli (deprecated, now awx-cli) or the newer awx CLI tool.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
Iโ€™m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Top 10 No-Code Platforms Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, no-code platforms have become essential for businesses and individuals looking to build powerful applications, websites, and automations without the need for programming knowledge. These…

Read More

Top 10 AI Training Data Platforms Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, AI training data platforms have become the backbone of successful machine learning (ML) and artificial intelligence (AI) projects. These platforms streamline the process of…

Read More

Top 10 AI Poster & Flyer Design Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, AI-powered poster and flyer design tools have revolutionized the way businesses, marketers, educators, and creators produce visually stunning promotional materials. These tools leverage artificial…

Read More

Top 10 Collaboration Platforms Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, collaboration platforms are more essential than ever. As remote and hybrid work environments continue to thrive, having the right collaboration tool can be the…

Read More

The 5 Most Popular Email APIs Among Developers In 2026

In the modern world, where everything is going digital, email is among the most important means of communication both in personal and business life. As a developer,…

Read More

Top 10 Construction Management Software Tools in 2026: Features, Pros, Cons & Comparison

Introduction Construction Management Software (CMS) has become indispensable in 2026 for efficiently handling various aspects of construction projects, ranging from budgeting, scheduling, resource allocation, project tracking, to…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x