summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/ansible-runner/files/adhoc_example1.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 16:04:21 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 16:04:21 +0000
commit8a754e0858d922e955e71b253c139e071ecec432 (patch)
tree527d16e74bfd1840c85efd675fdecad056c54107 /test/integration/targets/ansible-runner/files/adhoc_example1.py
parentInitial commit. (diff)
downloadansible-core-8a754e0858d922e955e71b253c139e071ecec432.tar.xz
ansible-core-8a754e0858d922e955e71b253c139e071ecec432.zip
Adding upstream version 2.14.3.upstream/2.14.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/integration/targets/ansible-runner/files/adhoc_example1.py')
-rw-r--r--test/integration/targets/ansible-runner/files/adhoc_example1.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/integration/targets/ansible-runner/files/adhoc_example1.py b/test/integration/targets/ansible-runner/files/adhoc_example1.py
new file mode 100644
index 0000000..ab24bca
--- /dev/null
+++ b/test/integration/targets/ansible-runner/files/adhoc_example1.py
@@ -0,0 +1,29 @@
+from __future__ import (absolute_import, division, print_function)
+__metaclass__ = type
+
+import json
+import os
+import sys
+import ansible_runner
+
+# the first positional arg should be where the artifacts live
+output_dir = sys.argv[1]
+
+# this calls a single module directly, aka "adhoc" mode
+r = ansible_runner.run(
+ private_data_dir=output_dir,
+ host_pattern='localhost',
+ module='shell',
+ module_args='whoami'
+)
+
+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)