ansible/ansible-runner

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

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Ansible Runner

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.

Basic Evaluation Usage

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

Understanding the Ansible Runner Directory Hierarchy Interface

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:

Input Directory Structure

The directory structure provided as an input for Runner looks like this


artifacts
env
??? envvars
??? extravars
??? passwords
??? settings
??? ssh_key
inventory
??? hosts
project
??? test.yml
Output Directory Structure

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

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 Runner as a Container Image

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.

Building the base container image

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

Ansible Runner as a Python Interface

p install ansible-runner

The runner module exposes two interfaces:

Example:

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:

Building the source distribution

To generate a source .whl distribution:

ke dist


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.