Ansible Runner Python

Ansible is written in its own API so you have a considerable amount of power across the board. This chapter discusses the Python API. The Python API is very powerful, and is how the ansible CLI and ansible-playbook are implemented. In version 2.0 the core ansible got rewritten and the API was mostly rewritten. The content was moved to my personal blog: Sorry for the inconvenience. Ansible Runner is a tool and python library that helps when interfacing with Ansible directly or as part of another system whether that be through a container image interface, as a standalone tool, or as a Python module that can be imported. The goal is to provide a stable and consistent interface abstraction to Ansible. Using Runner as a Python Module Interface to Ansible. Ansible Runner is intended to provide a directly importable and usable API for interfacing with Ansible itself and exposes a few helper interfaces. The modules center around the Runner object. The helper methods will either return an instance of this object which provides an interface to. Ansiblerunner.runner.Runner.stats is a property that will return the final playbook stats event from Ansible in the form of a Python dict Runner.hostevents ¶ ansiblerunner.runner.Runner.hostevents is a method that, given a hostname, will return a list of only Ansible event data executed on that Host.


Using Ansible content that depends on non-default dependencies can be tricky.Packages must be installed on each node, play nicely with other software installedon the host system, and be kept in sync.

To help simplify this process, we have introduced the concept of ExecutionEnvironments, which you can create with Ansible Builder.

Execution Environments¶

Execution Environments are container images that serve as Ansible controlnodes. Starting in version 2.0, ansible-runnercan make use of these images.

An Execution Environment is expected to contain:

  • Ansible
  • Ansible Runner
  • Ansible Collections
  • Python and/or system dependencies of:
    • modules/plugins in collections
    • content in ansible-base
    • custom user needs

Getting Started¶

To get started with Ansible Builder, start by creating anExecution Environment definition. Thisfile allows you to specify which content you would like to include in yourexecution environment, such as collections, Python requirements, andsystem-level packages.

Ansible Runner Python Programming

Ansible runner python download

Once you have created a definition, read through the CLI Usage.

Collection Developers¶

Collection developers can declare requirements for their content by providingthe appropriate metadata. For more information, seeCollection-level Metadata.

Ansible Runner Python Example


  • Installation
  • Execution Environment Definition
  • CLI Usage
    • Container build command
  • Collection-level Metadata
Comments are closed.