Name: ansible-runner
Owner: Ansible
Description: null
Created: 2018-02-02 15:17:40.0
Updated: 2018-05-15 01:26:31.0
Pushed: 2018-05-15 13:04:01.0
Homepage: null
Size: 148
Language: Python
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Ansible Runner is a tool and python library that helps when interfacing with Ansible from other systems whether through a container image interface, as a standalone tool, or imported into a python project.
The base reference container image includes a demo playbook and inventory that uses a local connection to demonstrate basic functionality.
cker run -it --rm -e RUNNER_PLAYBOOK=test.yml ansible/ansible-runner:latest
Ansible Runner takes most of its inputs from a particular directory structure. Some inputs can also be given on the command line. Primarily the ansible-runner
command line utility requires at least two parameters:
artifacts
directoryartifacts
directoryThe directory structure provided as an input for Runner looks like this
artifacts
env
??? envvars
??? extravars
??? passwords
??? settings
??? ssh_key
inventory
??? hosts
project
??? test.yml
-e
parameters to ansible-playbook
meaning they will take precedence over any other variables defined elsewhere. (see ./demo/env/extravars)ansible-playbook
. If the pattern is matched then the corresponding password will be emitted. (see ./demo/env/passwords)ansible-playbook
the runner will terminate the processansible-playbook
process runs for longer than this number of seconds then it will be automatically terminatedssh-agent
as part of the ansible-playbook
execution.ansible
itself and will be passed as the inventory argument. The behavior is for Ansible to recurse into this directory and evaluate all files and scripts to generate inventory content. If your needs are pretty simple then you can create a simple file in this directory that contains a list of hosts/groups. Note: If the --hosts argument is given to ansible-runner it will override ansible-playbook and this directory will not be given
cwd
when ansible-playbook
starts.As Runner executes it will write data into an artifacts directory using an identifier that is generated at runtime (or can be provided if ansible-runner
is supplied with the -i, --ident
command line argument), here's an example of a run of the demo playbook
artifacts
??? 2d6a3ae1-e5de-4d4e-8e9e-eb237494b592
??? daemon.log
??? job_events
? ??? 0242ac11-0003-deb5-53a0-000000000006-partial.json
? ??? 0242ac11-0003-deb5-53a0-000000000008-partial.json
? ??? 0242ac11-0003-deb5-53a0-00000000000d-partial.json
? ??? 33d9ee70-9e86-4023-ab83-ac4c776d503a-partial.json
? ??? 7cd6f879-9429-4e3c-ba9a-1df98cad83f6-partial.json
? ??? 811f7983-a5e8-4ca5-8406-d39ae1088c1d-partial.json
? ??? d5ac258b-ec43-465c-bdc3-0ac273061ef9-partial.json
??? rc
??? status
??? stdout
ansible-runner
itselfplaybook_on_stats
event:
uid": "d5ac258b-ec43-465c-bdc3-0ac273061ef9",
reated": "2018-03-01T18:22:47.937822",
id": 148,
vent_data": {
"skipped": {
},
"ok": {
"localhost": 2
},
"artifact_data": {
},
"changed": {
},
"pid": 148,
"dark": {
},
"playbook_uuid": "811f7983-a5e8-4ca5-8406-d39ae1088c1d",
"playbook": "test.yml",
"failures": {
},
"processed": {
"localhost": 1
}
vent": "playbook_on_stats"
ansible-playbook
processansible-playbook
raw stdout stripped of control characters.Runner's existing container image is meant to be used as a base or reference container image. It includes a simple playbook and inventory with extra vars that it forces to run under a local collection.
The container image itself exposes several directories as volumes and those can be used to replace the metadata contexts given to the execution of the runner.
Start by building the source distribution:
ke dist
Then construct the container image:
ke image
By default the image is named ansible-runner
which can be overridden by setting IMAGE_NAME
p install ansible-runner
The runner module exposes two interfaces:
ansible_runner.run()
- Invokes runner in the foreground and returns a Runner object that can be used
to inspect the runansible_runner.run_async()
- Invokes runner in a thread and returns the thread object and Runner object as a tupleExample:
import ansible_runner
r = ansible_runner.run(private_data_dir="/tmp/demo", playbook="test.yml")
[all] *********************************************************************
[Gathering Facts] *********************************************************
[localhost]
[debug] *******************************************************************
[localhost] => {
"msg": "Test!"
RECAP *********************************************************************
r.status
cessful'
r.rc
The Runner object that's returned has a few interfaces that are useful:
stdout
: Returns a file-handle to the stdout representing the Ansible run.events
: A generator that will return all ansible job events in the order that they were emitted from Ansiblestats
: Returns the final high level stats from the Ansible runhost_events()
: Given a host name, this will return all task events executed on the hostTo generate a source .whl
distribution:
ke dist