Ansible Runner Python

Latest version

Released:

I'm trying to run a python script from an ansible script. I would think this would be an easy thing to do, but I can't figure it out. I've got a project structure like this: playbook-folder roles stagecode files mypythonscript.py tasks main.yml release.yml.

  1. Apr 13, 2016 I have an ansible server that I find works fine, but when I try to run a python script on the deployed servers I get no such file or directory, even though I visually confirm they are there.
  2. Execution Environments are container images that serve as Ansible control nodes. Starting in version 2.0, ansible-runner can 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.
  3. Running Ansible playbook. Running a playbook is as easy as issuing the following command: $ ansible-playbook -i inventory installpython.yml. In the above ansible-playbook command we give our own inventory using ā€œ-iā€ flag. After running this command you will see the below output.
  4. The content was moved to my personal blog: Sorry for the inconvenience.

'Consistent Ansible Python API and CLI with container and process isolation runtime capabilities'

Project description

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.

For the latest documentation see: https://ansible-runner.readthedocs.io

  • We use GitHub issues to track bug report and feature ideas...
  • ... and GitHub Milestones to track what's for the next release
  • Want to contribute, check out our guide
  • Join us in the #ansible-runner channel on Libera.chat IRC
  • Join the discussion in awx-project
  • For the full list of Ansible email Lists, IRC channels see the Ansible Mailing lists

Release historyRelease notifications | RSS feed

2.0.2

2.0.1

2.0.0

2.0.0.0rc3 pre-release

2.0.0.0rc2 pre-release

Ansible runner python tutorial

2.0.0.0rc1 pre-release

2.0.0.0b1 pre-release

2.0.0.0a5 pre-release

2.0.0a4 pre-release

2.0.0a3 pre-release

2.0.0a2 pre-release

2.0.0a1 pre-release

1.4.7

1.4.6

1.4.5

1.4.4

1.4.2

1.4.1

1.4.0

1.3.4

1.3.3

1.3.2

1.3.1

1.3.0

1.2.0

1.1.2

1.1.1

1.1.0

1.0.5

1.0.4

1.0.3

1.0.2

1.0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ansible-runner, version 2.0.2
Filename, sizeFile typePython versionUpload dateHashes
Filename, size ansible_runner-2.0.2-py3-none-any.whl (77.9 kB) File type Wheel Python version py3 Upload dateHashes
Filename, size ansible-runner-2.0.2.tar.gz (144.8 kB) File type Source Python version None Upload dateHashes
Close

Hashes for ansible_runner-2.0.2-py3-none-any.whl

Hashes for ansible_runner-2.0.2-py3-none-any.whl
AlgorithmHash digest
SHA256a6e7d108b6445425a3086942816bb3b252efb253a1536cedb065391897c574fa
MD512d81a13b5eabd96e233d4ca81b7016c
BLAKE2-256c61b2ed2d3b76277402c49c93f95a1fe317fefde256ddf9d7504eeae440a78f9
Close

Hashes for ansible-runner-2.0.2.tar.gz

Hashes for ansible-runner-2.0.2.tar.gz
AlgorithmHash digest
SHA256c02b690803ec0be4453411c53743cd3fdca1dfc66dfa075794e14e717c5b61b3
MD58a26b02132848b765f785ff56e90e49d
BLAKE2-256d7e21ece0627d214cd8c47fc28a0d64ada7be71cd8e614a76492b1aa1fafbe8a
SUMMARY

At this moment, Ansible would fail to run on most remote hosts that do only have python3 installed by default, like Fedora 27 or newer, unless the user exclicitely adds the ansible_python_interpreter=python3 inside the inventory.

This is a real issue because it assumes that the user already knows which is the default ansible interpreter on that host, which may not be something he knows or even controls. Think about dynamic inventories or playbooks that would upgrade a host from a version that had python2 to one that that has python3.

Python
ISSUE TYPE
  • Feature Idea
COMPONENT NAME

core

ADDITIONAL INFORMATION

This issue was aggravated by the recommandation made https://www.python.org/dev/peps/pep-0394/ which indirectly made newer distributions which ship with python3 by default to not create a symlink from python to python3, even when there was no python2 installed.

Ansible Runner Example

As it seems highly unlikely to be able to update the PEP with new recomandations, we should look into findina solution for ansible, one that does not cripple the UX and avoids the need to tune ansible_python_interpreter variable for each host. This should happen under the hood by detecting a missing interpreter and falling back to python3 one (caching may be desired too).

Related links

Ansible With Python

  • https://github.com/python/peps/pull/630 - Last merged change to PEP-0394 (April 2018)
  • https://github.com/python/peps/pull/785 - Request to update PEP-0394
  • https://bugzilla.redhat.com/show_bug.cgi?id=1630882 - Request to add python symlink to Fedora
  • https://wiki.ubuntu.com/Python/3 - Ubuntu not creating the symlink because of PEP-0394