Ansible Runner Integration
Much of the code in AWX around Ansible andansible-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
-
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)
-
Build Temp Directory: A temporary directory is created to house ansible-runner parameters
-
Populate Directory: Fill with AWX concepts
- SSH keys
- Extra vars
- Environment variables
- Credentials
- Playbook files
-
Build Parameters: Create parameters for
ansible-runner.interface.run() -
Pass Control to ansible-runner: AWX calls
ansible-runner.interface.run()- Passes callbacks and handlers
- ansible-runner spawns ansible-playbook
- Monitors execution
- Collects events
- 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.cancel_callback
Called periodically by ansible-runner to check if the job should be canceled.finished_callback
Called once by ansible-runner when the process finishes.status_handler
Called as ansible-runner transitions through internal states.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:Process Monitoring
When spawned:- Process runs until completion or timeout
- Return code,
stdout, andstderrrecorded - 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_startplaybook_on_play_startplaybook_on_task_startrunner_on_okrunner_on_failedrunner_on_skippedrunner_on_unreachableplaybook_on_stats
Event Data Structure
Example event:- 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
- Ansible playbook runs with fact caching enabled
- jsonfile cache plugin writes facts to disk
- After ansible-playbook exits, AWX consumes the cache
- Facts persisted to AWX database
- On subsequent runs, AWX restores cache to filesystem
- 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: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 runansible-inventory to fetch inventory data.
Inventory Sync Process
- Create inventory config (YAML or INI)
- Set up credentials (environment variables)
- Run ansible-inventory:
- Parse JSON output
- 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:-
Set environment variable:
- Run a job
-
Find the data directory:
- Inspect directory on the execution node
Job Execution Parameters
To debug the Ansible process:Event Debugging
Check event processing:Compatibility Considerations
AWX strives to support multiple Ansible versions, but relies on stability in:CLI Interfaces
ansible-playbookarguments and behavioransible-inventoryoutput formatansible(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
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