Questions tagged [ansible-runner]

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.

More information about Ansible Runner is available at:

  1. https://github.com/ansible/ansible-runner
  2. https://ansible-runner.readthedocs.io/en/latest/

For information on the larger Ansible project, see: https://stackoverflow.com/tags/ansible/info

22 questions
42
votes
5 answers

Running ansible-playbook using Python API

How can I run a playbook in python script? What is the equivalent of the following using ansible module in python: ansible -i hosts dbservers -m setup ansible-playbook -i hosts -vvvv -k site.yml I was looking at their documenation in…
helloworld2013
  • 3,094
  • 5
  • 19
  • 26
9
votes
3 answers

How do I drive Ansible programmatically and concurrently?

I would like to use Ansible to execute a simple job on several remote nodes concurrently. The actual job involves grepping some log files and then post-processing the results on my local host (which has software not available on the remote…
3
votes
1 answer

Enable Apache site using Ansible

I am running a playbook from a python script. I am following this code The following command works perfectly. ansible -i path/to/inventory.yml host_name -m command -a"a2ensite site_name" But when I try to do the same by executing a playbook from…
Amarjit Singh
  • 2,068
  • 19
  • 52
2
votes
1 answer

Passing nested dictionary as extra_vars to ansible-playbooks

I want to pass a huge nested dictionary as an extra_vars to an Ansible playbook. I want to use values from that dictionary in my playbook. sample_dict = { 'student' : {'name' : 'coder', 'marks' : 100} } I want to pass this dictionary as an…
Pranav Barve
  • 105
  • 1
  • 7
2
votes
0 answers

How to read the events from ansible runner programatically

I use ansible runner to trigger an ansible-playbook from a django application, which runs fine. See the following code. import ansible_runner def runner(request): r = ansible_runner.run_async(private_data_dir='/Users/path/to/private_dir', …
Shobi
  • 10,374
  • 6
  • 46
  • 82
1
vote
1 answer

How to get unreachable nodes after ansible playbook execution in python?

After executing an ansible playbook, I need the node names that were not reached. I thought about using AnsibleRunner for running the ansible-playbook and I know of the special variables ansible_play_hosts and ansible_play_hosts_all which you can…
Natan
  • 728
  • 1
  • 7
  • 23
1
vote
1 answer

Ansible Runner can't execute playbook

I am trying execute an ansible playbook inside a Flask Python project using ansible runner but upon execution, I get the following error: The command was not found or was not executable: ansible-playbook. The app runs in a docker container inside…
Omar Abdelrazik
  • 683
  • 2
  • 9
  • 30
1
vote
2 answers

Pass a list as inventory to ansible_runner python module

I want to use ansible_runner to do some parsing on hosts. I have a script which gathers a list of hosts from a database and then I want to pass that list to ansible_runner python module without writing the "inventory" to disk. I tried to do like…
danidar
  • 179
  • 2
  • 10
1
vote
0 answers

Error while executing ansible playbook with python

I have a playbook that works fine if I run using ansible-playbook command. But I want to execute this playbook from a python script So I created a function in python that takes a path to the inventory file and a path to the playbook file. from…
Amarjit Singh
  • 2,068
  • 19
  • 52
1
vote
2 answers

Write Ansible playbooks using Python dictionary

I am trying execute the following playbook using python script. playbook = dict( name = "Enable Site", hosts = [host], gather_facts = 'no', tasks = [ dict(action=dict( module='find',…
Amarjit Singh
  • 2,068
  • 19
  • 52
1
vote
2 answers

Ansible weird error : The error was: 'str object' has no attribute 'ip'

I have a very strange problem with an Ansible playbook. I use ansible with a Flask API, so I use ansible-runner to pass my variables to my playbook. My playbook is just a debug of my dictionary and its ip attribute: - hosts: localhost connection:…
Genils
  • 13
  • 1
  • 4
1
vote
1 answer

In the ansible_runner python library, is it possible to retrieve registered variable from the playbooks with the runner?

I started using the ansible_runner python library and i really like it. https://github.com/ansible/ansible-runner https://ansible-runner.readthedocs.io/en/latest/ The only thing is that I need to retrieve a registered variable. And I just can't…
Stfb
  • 11
  • 3
1
vote
1 answer

ansible runner runs to long

When I use ansible's python API to run a script on remote machines(thousands), the code is: runner = ansible.runner.Runner( module_name='script', module_args='/tmp/get_config.py', pattern='*', forks=30 ) then, I use datastructure =…
page
  • 52
  • 6
1
vote
2 answers

Could not make dir /$HOME/.ansible/cp: [Errno 13] Permission denied: '/$HOME

I've got a python script that uses the ansible package to ping some remote servers. When executed manually (python devmanager.py) it works ok, but when the script is managed with supervisor it raises the following error: Could not make dir…
klautern
  • 129
  • 3
  • 7
  • 26
1
vote
1 answer

How can I run an ansible play programmatically while still using a local file as my play?

Setup/Contraints I want to run an ansible play located at /tmp/run_tests.yml and I want to perform the run in a python script, not command line (these are general constraints on the problem I am working on). I;ve tried several different approaches…
Victor 'Chris' Cabral
  • 2,135
  • 1
  • 16
  • 33
1
2