diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:03:01 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:03:01 +0000 |
commit | a453ac31f3428614cceb99027f8efbdb9258a40b (patch) | |
tree | f61f87408f32a8511cbd91799f9cececb53e0374 /test/integration/targets/ansible-runner/files/playbook_example1.py | |
parent | Initial commit. (diff) | |
download | ansible-a453ac31f3428614cceb99027f8efbdb9258a40b.tar.xz ansible-a453ac31f3428614cceb99027f8efbdb9258a40b.zip |
Adding upstream version 2.10.7+merged+base+2.10.8+dfsg.upstream/2.10.7+merged+base+2.10.8+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/integration/targets/ansible-runner/files/playbook_example1.py')
-rw-r--r-- | test/integration/targets/ansible-runner/files/playbook_example1.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/integration/targets/ansible-runner/files/playbook_example1.py b/test/integration/targets/ansible-runner/files/playbook_example1.py new file mode 100644 index 00000000..83cb19ff --- /dev/null +++ b/test/integration/targets/ansible-runner/files/playbook_example1.py @@ -0,0 +1,38 @@ +import json +import os +import sys +import ansible_runner + + +PLAYBOOK = ''' +- hosts: localhost + gather_facts: False + tasks: + - set_fact: + foo: bar +''' + +# the first positional arg should be where the artifacts live +output_dir = sys.argv[1] + +invdir = os.path.join(output_dir, 'inventory') +if not os.path.isdir(invdir): + os.makedirs(invdir) +with open(os.path.join(invdir, 'hosts'), 'w') as f: + f.write('localhost\n') +pbfile = os.path.join(output_dir, 'test.yml') +with open(pbfile, 'w') as f: + f.write(PLAYBOOK) + +r = ansible_runner.run(private_data_dir=output_dir, playbook='test.yml') + +data = { + 'rc': r.rc, + 'status': r.status, + 'events': [x['event'] for x in r.events], + 'stats': r.stats +} + +# insert this header for the flask controller +print('#STARTJSON') +json.dump(data, sys.stdout) |