diff options
author | Matt Clay <matt@mystile.com> | 2019-08-28 03:11:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-28 03:11:21 +0200 |
commit | f510d59943f7f00f74e42ad78780e9e89787e991 (patch) | |
tree | 1402467d68a20d992da936598569f1e07874571b /hacking/test-module.py | |
parent | win_updates: Add flag to only download updates without installing them (#58631) (diff) | |
download | ansible-f510d59943f7f00f74e42ad78780e9e89787e991.tar.xz ansible-f510d59943f7f00f74e42ad78780e9e89787e991.zip |
Support relative imports in AnsiballZ. (#61196)
Diffstat (limited to 'hacking/test-module.py')
-rwxr-xr-x | hacking/test-module.py | 14 |
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 |