summaryrefslogtreecommitdiff
path: root/hacking/test-module.py
diff options
context:
space:
mode:
authorMatt Clay <matt@mystile.com>2019-08-27 18:11:21 -0700
committerGitHub <noreply@github.com>2019-08-27 18:11:21 -0700
commitf510d59943f7f00f74e42ad78780e9e89787e991 (patch)
tree1402467d68a20d992da936598569f1e07874571b /hacking/test-module.py
parent5549788c8d30d868fb249ac056100aa21dbf79a0 (diff)
downloadansible-f510d59943f7f00f74e42ad78780e9e89787e991.tar.gz
Support relative imports in AnsiballZ. (#61196)
Diffstat (limited to 'hacking/test-module.py')
-rwxr-xr-xhacking/test-module.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/hacking/test-module.py b/hacking/test-module.py
index 72b387cc92..1a063082fd 100755
--- a/hacking/test-module.py
+++ b/hacking/test-module.py
@@ -28,6 +28,7 @@
# ./hacking/test-module.py -m lib/ansible/modules/files/lineinfile.py -a "dest=/etc/exports line='/srv/home hostname1(rw,sync)'" --check
# ./hacking/test-module.py -m lib/ansible/modules/commands/command.py -a "echo hello" -n -o "test_hello"
+import glob
import optparse
import os
import subprocess
@@ -193,8 +194,19 @@ def ansiballz_setup(modfile, modname, interpreters):
sys.exit(err)
debug_dir = lines[1].strip()
+ # All the directories in an AnsiBallZ that modules can live
+ core_dirs = glob.glob(os.path.join(debug_dir, 'ansible/modules'))
+ collection_dirs = glob.glob(os.path.join(debug_dir, 'ansible_collections/*/*/plugins/modules'))
+
+ # There's only one module in an AnsiBallZ payload so look for the first module and then exit
+ for module_dir in core_dirs + collection_dirs:
+ for dirname, directories, filenames in os.walk(module_dir):
+ for filename in filenames:
+ if filename == modname + '.py':
+ modfile = os.path.join(dirname, filename)
+ break
+
argsfile = os.path.join(debug_dir, 'args')
- modfile = os.path.join(debug_dir, '__main__.py')
print("* ansiballz module detected; extracted module source to: %s" % debug_dir)
return modfile, argsfile