Here is my code: I am not able to run a ansible module using python. How to pass a inventory file for which this command is running. I am not able to run it for my inventory. Do I need to do something else ? Here is my ansible command:
ansible all -i /home/ubuntu/extra -m 'debug' -a 'var=hostvars'
Here is my code:
import json
import ansible.runner
import ansible.playbook
import ansible.inventory
hosts = ["10.12.11.101"]
example_inventory = ansible.inventory.Inventory(hosts)
pm = ansible.runner.Runner( module_name = 'debug', module_args = 'vars=hostvars', timeout = 5, inventory = example_inventory, subset = 'all')
out = pm.run()
print json.dumps(out, sort_keys=True, indent=4, separators=(',', ': '))