Skip to content

AWX / Tower

Deploying Ansible playbooks to AWX/Tower enables centralized orchestration, scheduling, and execution of automation workflows. This section covers integration strategies using the AWX/Tower API, including playbook deployment, job scheduling, and best practices for production use.


Deploying Playbooks to AWX/Tower

To deploy playbooks, use the AWX/Tower REST API to upload files and create job templates. Ensure your environment meets these prerequisites: - AWX/Tower instance is running and accessible. - API access credentials (e.g., a personal access token). - Playbooks stored in a version-controlled repository (e.g., Git).

Uploading Playbooks via API

Use curl to upload a playbook to a project in AWX/Tower:

curl -X POST \
  https://{tower_url}/api/v2/projects/1/ \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "my-playbook-project",
    "scm_type": "git",
    "scm_url": "https://github.com/example/playbooks.git",
    " scm_branch": "main"
  }'
Replace {tower_url} and {token} with your instance's URL and API token. This registers a Git repository as a project source.

Creating Job Templates

After deployment, create a job template to define execution parameters:

curl -X POST \
  https://{tower_url}/api/v2/job_templates/ \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "deploy-app",
    "job_type": "run",
    "playbook": "/home/user/playbooks/deploy.yml",
    "inventory": "my-inventory",
    "credential": "my-credential"
  }'
This associates the playbook with an inventory and credentials, enabling execution.


Scheduling Playbook Execution

AWX/Tower supports scheduling via the API or the web UI. For automation, use the /api/v2/jobs/ endpoint to trigger jobs:

curl -X POST \
  https://{tower_url}/api/v2/jobs/ \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json" \
  -d '{
    "job_template": 1,
    "inventory": 1,
    "credential": 1,
    "extra_vars": "{\"env\": \"production\"}"
  }'
This initiates a job using the specified template, inventory, and credentials. Use extra_vars to pass dynamic parameters.

For recurring schedules, configure job templates with a schedule in the web UI or via the API's /api/v2/job_templates/ endpoint.


Best Practices

  • Version Control: Store playbooks in Git and use AWX/Tower's project integration for automatic sync.
  • Inventory Management: Define reusable inventory sources to avoid duplication.
  • Security: Rotate API tokens regularly and restrict permissions to minimize exposure.
  • Monitoring: Use AWX/Tower's built-in job status tracking and alerting.

Key takeaways

  • Deploy playbooks via the AWX/Tower API by registering Git repositories and creating job templates.
  • Schedule executions using the API or web UI, leveraging job templates for recurring tasks.
  • Prioritize version control, inventory reuse, and token security for production workflows.