Skip to main content
AWX is built on top of Ansible and relies heavily on Ansible’s interfaces. This document explains the touchpoints between AWX and Ansible, focusing on how AWX spawns and interacts with Ansible processes.

Ansible Runner Integration

Much of the code in AWX around Ansible and ansible-playbook invocation has been moved to the ansible-runner project. AWX now calls out to ansible-runner to invoke Ansible.
ansible-runner is a separate project that provides a stable interface for running Ansible playbooks and handling their output.

Why Ansible Runner?

Benefits:
  • Separates execution logic from AWX core
  • Provides stable interface for playbook execution
  • Handles process isolation and containerization
  • Manages input/output consistently
  • Reusable by other projects

Job Execution Lifecycle

High-Level Flow

Detailed Lifecycle

  1. Task Kicked Off: A task of a certain job type is started in awx/main/tasks/jobs.py
    • RunJob (Job Template execution)
    • RunProjectUpdate (SCM update)
    • RunInventoryUpdate (Inventory sync)
    • RunAdHocCommand (Ad hoc command)
  2. Build Temp Directory: A temporary directory is created to house ansible-runner parameters
  3. Populate Directory: Fill with AWX concepts
    • SSH keys
    • Extra vars
    • Environment variables
    • Credentials
    • Playbook files
  4. Build Parameters: Create parameters for ansible-runner.interface.run()
  5. Pass Control to ansible-runner: AWX calls ansible-runner.interface.run()
    • Passes callbacks and handlers
    • ansible-runner spawns ansible-playbook
    • Monitors execution
    • Collects events
  6. Gather Feedback: Via callbacks and handlers

Callbacks and Handlers

AWX provides several callbacks to ansible-runner for event handling:

event_handler

Called each time a new event is created in ansible-runner.
Purpose: AWX dispatches events to Redis to be processed by the callback receiver, which saves them to the database.

cancel_callback

Called periodically by ansible-runner to check if the job should be canceled.
Purpose: Allows AWX to inform ansible-runner if the job should be canceled. Mainly used for system jobs now; other jobs are canceled via Receptor.

finished_callback

Called once by ansible-runner when the process finishes.
Purpose: Signals that the process is complete, including the total number of events observed.

status_handler

Called as ansible-runner transitions through internal states.
Purpose: AWX uses the starting status to know that ansible-runner has finalized execution parameters. These are saved for historical observation.

Spawning Ansible Processes

CLI Stability

AWX relies on stable interfaces for: ansible-playbook:
ansible-inventory:
ansible (for ad hoc commands):

Process Monitoring

When spawned:
  • Process runs until completion or timeout
  • Return code, stdout, and stderr recorded
  • Timeout is configurable per job template
  • Process runs in container/pod for isolation

Command Construction

AWX builds the command line based on Job Template settings:

Capturing Event Data

Callback Plugin

AWX applies an Ansible callback plugin to all spawned processes: Location: awx/plugins/callback/awx.py Functionality:
  • Intercepts Ansible events
  • Formats event data as JSON
  • Sends to callback receiver
  • Enables real-time streaming

Event Flow

Event Types

Common Ansible events captured:
  • playbook_on_start
  • playbook_on_play_start
  • playbook_on_task_start
  • runner_on_ok
  • runner_on_failed
  • runner_on_skipped
  • runner_on_unreachable
  • playbook_on_stats

Event Data Structure

Example event:
AWX relies on stability in:
  • Plugin interface
  • Event hierarchy based on strategy
  • Structure of event data

Fact Caching

AWX provides custom fact caching to persist facts across job runs.

How It Works

  1. Ansible playbook runs with fact caching enabled
  2. jsonfile cache plugin writes facts to disk
  3. After ansible-playbook exits, AWX consumes the cache
  4. Facts persisted to AWX database
  5. On subsequent runs, AWX restores cache to filesystem
  6. New ansible-playbook uses existing facts

Configuration

Benefits

  • Faster playbook runs: Skip gathering facts if cached
  • Cross-job persistence: Facts available to all jobs
  • Reduced target load: Less frequent fact gathering

Environment-Based Configuration

Credential Injection

AWX injects credentials via environment variables:

Ansible Configuration

AWX sets Ansible configuration via environment:

Module Configuration

Module-specific settings:
AWX relies on stability in these environment variable names across Ansible versions.

Project Updates

Project updates are also Ansible playbook runs.

SCM Update Playbook

AWX includes a playbook for SCM operations: Location: awx/playbooks/project_update.yml Functionality:
  • Clones git repositories
  • Updates existing checkouts
  • Handles authentication
  • Validates playbook structure

SCM Credentials

Injected similarly to other credentials:

Inventory Updates

Inventory updates run ansible-inventory to fetch inventory data.

Inventory Sync Process

  1. Create inventory config (YAML or INI)
  2. Set up credentials (environment variables)
  3. Run ansible-inventory:
  4. Parse JSON output
  5. Import to AWX database as Hosts and Groups

Inventory Plugins

AWX supports various inventory plugins:
  • Cloud providers: AWS EC2, Azure, GCP, OpenStack
  • Virtualization: VMware, oVirt
  • Container platforms: OpenShift, Kubernetes
  • Custom sources: Controller (AWX-to-AWX), constructed

Credential Injection

Inventory credentials injected as environment variables:

Debugging Ansible Integration

AWX_PRIVATE_DATA_DIR

To debug ansible-runner:
  1. Set environment variable:
  2. Run a job
  3. Find the data directory:
  4. Inspect directory on the execution node

Job Execution Parameters

To debug the Ansible process:
This shows exactly how ansible-playbook was invoked.

Event Debugging

Check event processing:

Compatibility Considerations

AWX strives to support multiple Ansible versions, but relies on stability in:

CLI Interfaces

  • ansible-playbook arguments and behavior
  • ansible-inventory output format
  • ansible (ad hoc) command interface

Callback Plugin Interface

  • Plugin method signatures
  • Event data structures
  • Event ordering and hierarchy

Configuration Options

  • Environment variables
  • ansible.cfg settings
  • Module parameters

Fact Cache Format

  • jsonfile cache structure
  • Fact data schema
When upgrading Ansible, test thoroughly to ensure AWX compatibility, especially around callback plugins and CLI behavior.

Execution Environments

Modern AWX uses Execution Environments (container images) to run Ansible:
  • Consistent Ansible version
  • Bundled collections and dependencies
  • Isolated from AWX control plane
  • Supports multiple Ansible versions simultaneously
See the Execution Environments documentation for more details.

Next Steps