2019-09-17 22:49:01 +03:00
# AWX
AWX provides a web interface and distributed task engine for scheduling and
2018-01-31 21:12:54 +03:00
running Ansible playbooks. As such, it relies heavily on the interfaces
provided by Ansible. This document provides a birds-eye view of the notable
2019-09-17 22:49:01 +03:00
touchpoints between AWX and Ansible.
2018-01-31 21:12:54 +03:00
## Terminology
2019-09-17 22:49:01 +03:00
AWX has a variety of concepts which map to components of Ansible, or
2018-01-31 21:12:54 +03:00
which further abstract them to provide functionality on top of Ansible. A few
of the most notable ones are:
2019-09-17 22:49:01 +03:00
2018-01-31 21:12:54 +03:00
### Projects
2019-09-17 22:49:01 +03:00
Projects represent a collection of Ansible playbooks. Most AWX users create
2018-01-31 21:12:54 +03:00
Projects that import periodically from source control systems (such as git,
mercurial, or subversion repositories). This import is accomplished via an
2019-09-17 22:49:01 +03:00
Ansible playbook included with AWX (which makes use of the various source
2018-01-31 21:12:54 +03:00
control management modules in Ansible).
2019-09-17 22:49:01 +03:00
2018-01-31 21:12:54 +03:00
### Inventories
2019-09-17 22:49:01 +03:00
AWX manages Inventories, Groups, and Hosts, and provides a RESTful interface
2018-01-31 21:12:54 +03:00
that maps to static and dynamic Ansible inventories. Inventory data can
2019-09-17 22:49:01 +03:00
be entered into AWX manually, but many users perform Inventory Syncs to import
2018-01-31 21:12:54 +03:00
inventory data from a variety of external sources.
2019-09-17 22:49:01 +03:00
2018-01-31 21:12:54 +03:00
### Job Templates
2019-09-17 22:49:01 +03:00
2018-01-31 21:12:54 +03:00
A Job Template is a definition and set of parameters for running
`ansible-playbook` . If defines metadata about a given playbook run, such as:
* a named identifier
* an associated inventory to run against
* the project and `.yml` playbook to run
2019-09-17 22:49:01 +03:00
* a variety of other options which map directly to `ansible-playbook`
arguments (`extra_vars`, verbosity, forks, limit, etc...)
2018-01-31 21:12:54 +03:00
### Credentials
2019-09-17 22:49:01 +03:00
AWX stores sensitive credential data which can be attached to `ansible-playbook`
2018-01-31 21:12:54 +03:00
processes that it runs. This data can be oriented towards SSH connection
2019-09-23 16:46:54 +03:00
authentication (usernames, passwords, SSH keys and passphrases),
2019-09-17 22:49:01 +03:00
Ansible-specific prompts (such as Vault passwords), or environmental
2018-01-31 21:12:54 +03:00
authentication values which various Ansible modules depend on (such as setting
`AWS_ACCESS_KEY_ID` in an environment variable, or specifying
`ansible_ssh_user` as an extra variable).
2019-09-17 22:49:01 +03:00
2018-01-31 21:12:54 +03:00
## Canonical Example
2019-09-17 22:49:01 +03:00
Bringing all of this terminology together, a "Getting Started Using AWX" might
2018-01-31 21:12:54 +03:00
involve:
2019-09-17 22:49:01 +03:00
* Creating a new Project that imports playbooks from, for example, a remote git repository
2018-01-31 21:12:54 +03:00
* Manually creating or importing an Inventory which defines where the playbook(s) will run
* Optionally, saving a Credential which contains SSH authentication details for
the host(s) where the playbook will run
* Creating a Job Template that specifies which Project and playbook to run and
2019-09-17 22:49:01 +03:00
where to run it (Inventory), and any necessary Credentials (*e.g.*, SSH
authentication)
2018-01-31 21:12:54 +03:00
* Launching the Job Template and viewing the results
2019-09-17 22:49:01 +03:00
## AWX's Interaction with Ansible
The touchpoints between AWX and Ansible are mostly encompassed by
everything that happens *after* a job is started in AWX. Specifically, this
2018-01-31 21:12:54 +03:00
includes:
* Any time a Job Template is launched
* Any time a Project Update is performed
* Any time an Inventory Sync is performed
* Any time an Adhoc Command is run
2019-09-17 22:49:01 +03:00
2018-01-31 21:12:54 +03:00
### Spawning Ansible Processes
2019-09-17 22:49:01 +03:00
AWX relies on a handful of stable interfaces in its interaction with Ansible.
2018-01-31 21:12:54 +03:00
The first of these are the actual CLI for `ansible-playbook` and
`ansible-inventory` .
2019-09-17 22:49:01 +03:00
When a Job Template or Project Update is run in AWX, an actual
2018-01-31 21:12:54 +03:00
`ansible-playbook` command is composed and spawned in a pseudoterminal on one
2019-09-17 22:49:01 +03:00
of the servers/containers that make up the AWX installation. This process runs
2018-01-31 21:12:54 +03:00
until completion (or until a configurable timeout), and the return code,
2019-09-17 22:49:01 +03:00
`stdout` , and `stderr` of the process are recorded in the AWX database. Ad hoc
2018-01-31 21:12:54 +03:00
commands work the same way, though they spawn `ansible` processes instead of
`ansible-playbook` .
Similarly, when an Inventory Sync runs, an actual `ansible-inventory` process
2019-09-17 22:49:01 +03:00
runs, and its output is parsed and persisted into the AWX database as Hosts and
2018-01-31 21:12:54 +03:00
Groups.
2019-09-17 22:49:01 +03:00
AWX relies on stability in CLI behavior to function properly across Ansible
2018-01-31 21:12:54 +03:00
releases; this includes the actual CLI arguments _and_ the behavior of task
2019-09-17 22:49:01 +03:00
execution and prompts (such as password, `become` , and Vault prompts).
2018-01-31 21:12:54 +03:00
### Capturing Event Data
2019-09-17 22:49:01 +03:00
AWX applies an Ansible callback plugin to all `ansible-playbook` and `ansible`
2018-01-31 21:12:54 +03:00
processes it spawns. This allows Ansible events to be captured and persisted
2019-09-17 22:49:01 +03:00
into the AWX database; this process is what drives the "streaming" web UI
you'll see if you launch a job from the AWX web interface and watch its results
appears on the screen. AWX relies on stability in this plugin interface, the
2018-01-31 21:12:54 +03:00
heirarchy of emitted events based on strategy, and _especially_ the structure
of event data to work across Ansible releases:
![Event Data Diagram ](https://user-images.githubusercontent.com/722880/35641610-ae7f1dea-068e-11e8-84fb-0f96043d53e4.png )
2019-09-17 22:49:01 +03:00
2018-01-31 21:12:54 +03:00
### Fact Caching
2019-09-17 22:49:01 +03:00
AWX provides a custom fact caching implementation that allows users to store
facts for playbook runs across subsequent Job Template runs. Specifically, AWX
2018-01-31 21:12:54 +03:00
makes use of the `jsonfile` fact cache plugin; after `ansible-playbook` runs
2019-09-17 22:49:01 +03:00
have exited, AWX consumes the entire `jsonfile` cache and persists it in the
AWX database. On subsequent Job Template runs, prior `jsonfile` caches are
2018-01-31 21:12:54 +03:00
restored to the local file system so the new `ansible-playbook` process makes
use of them.
2019-09-17 22:49:01 +03:00
2018-01-31 21:12:54 +03:00
### Environment-Based Configuration
2019-09-17 22:49:01 +03:00
AWX injects credentials and module configuration for a number of Ansible
2018-01-31 21:12:54 +03:00
modules via environment variables. Examples include:
* `ANSIBLE_NET_*` and other well-known environment variables for network device authentication
* API keys and other credential values which are utilized
(`AWS_ACCESS_KEY_ID`, `GCE_EMAIL` , etc...)
* SSH-oriented configuration flags, such as `ANSIBLE_SSH_CONTROL_PATH`
2019-09-17 22:49:01 +03:00
AWX relies on stability in these configuration options to reliably support
2018-01-31 21:12:54 +03:00
credential injection for supported Ansible modules.