I have simple playbook to fetch and copy files from a share to remote windows clients:
- name: Test chocolatey module
hosts: win_clones
vars_files:
- /
You can run the playbook from the Python API (though it's more code and Ansible doesn't officially support it for external callers). Use the example from Python API 2.0 as a baseline, and instead of loading a play, load a playbook:
from ansible.playbook import Playbook
playbook = Playbook(loader).load('fetch.yml' loader=loader, variable_manager=variable_manager)
Then substitute
result = tqm.run(play)
for this
for play in playbook.get_plays():
result = tqm.run(play)
You'll need some adaptation to get it to iterate multiple times per your for loop above, but this is the framework.
You can set stdout_callback = json
via configuration file or env variable ANSIBLE_STDOUT_CALLBACK
.
ansible-playbook
will print huge json file with execution result to stdout.