mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Push debug files into a subdirectory to keep things cleaner.
We now have the ansible module directory, ansible_module_*.py script file and the args file. Makes sense to push them all into a separate subdir.
This commit is contained in:
parent
e9553c975f
commit
3c135ef3f2
1 changed files with 11 additions and 3 deletions
|
@ -166,8 +166,10 @@ def debug(command, zipped_mod, json_params):
|
||||||
# $ /usr/bin/python /home/badger/.ansible/tmp/ansible-tmp-1461173013.93-9076457629738/ping execute
|
# $ /usr/bin/python /home/badger/.ansible/tmp/ansible-tmp-1461173013.93-9076457629738/ping execute
|
||||||
|
|
||||||
# Okay to use __file__ here because we're running from a kept file
|
# Okay to use __file__ here because we're running from a kept file
|
||||||
basedir = os.path.abspath(os.path.dirname(__file__))
|
basedir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'debug_dir')
|
||||||
args_path = os.path.join(basedir, 'args')
|
args_path = os.path.join(basedir, 'args')
|
||||||
|
script_path = os.path.join(basedir, 'ansible_module_%(ansible_module)s.py')
|
||||||
|
|
||||||
if command == 'explode':
|
if command == 'explode':
|
||||||
# transform the ZIPDATA into an exploded directory of code and then
|
# transform the ZIPDATA into an exploded directory of code and then
|
||||||
# print the path to the code. This is an easy way for people to look
|
# print the path to the code. This is an easy way for people to look
|
||||||
|
@ -205,13 +207,14 @@ def debug(command, zipped_mod, json_params):
|
||||||
# This differs slightly from default Ansible execution of Python modules
|
# This differs slightly from default Ansible execution of Python modules
|
||||||
# as it passes the arguments to the module via a file instead of stdin.
|
# as it passes the arguments to the module via a file instead of stdin.
|
||||||
|
|
||||||
|
# Set pythonpath to the debug dir
|
||||||
pythonpath = os.environ.get('PYTHONPATH')
|
pythonpath = os.environ.get('PYTHONPATH')
|
||||||
if pythonpath:
|
if pythonpath:
|
||||||
os.environ['PYTHONPATH'] = ':'.join((basedir, pythonpath))
|
os.environ['PYTHONPATH'] = ':'.join((basedir, pythonpath))
|
||||||
else:
|
else:
|
||||||
os.environ['PYTHONPATH'] = basedir
|
os.environ['PYTHONPATH'] = basedir
|
||||||
|
|
||||||
p = subprocess.Popen(['%(interpreter)s', 'ansible_module_%(ansible_module)s.py', args_path], env=os.environ, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
|
p = subprocess.Popen(['%(interpreter)s', script_path, args_path], env=os.environ, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
|
||||||
(stdout, stderr) = p.communicate()
|
(stdout, stderr) = p.communicate()
|
||||||
|
|
||||||
if not isinstance(stderr, (bytes, unicode)):
|
if not isinstance(stderr, (bytes, unicode)):
|
||||||
|
@ -236,8 +239,10 @@ def debug(command, zipped_mod, json_params):
|
||||||
# not actual bugs (as they don't affect the real way that we invoke
|
# not actual bugs (as they don't affect the real way that we invoke
|
||||||
# ansible modules)
|
# ansible modules)
|
||||||
|
|
||||||
# stub the
|
# stub the args and python path
|
||||||
sys.argv = ['%(ansible_module)s', args_path]
|
sys.argv = ['%(ansible_module)s', args_path]
|
||||||
|
sys.path.insert(0, basedir)
|
||||||
|
|
||||||
from ansible_module_%(ansible_module)s import main
|
from ansible_module_%(ansible_module)s import main
|
||||||
main()
|
main()
|
||||||
print('WARNING: Module returned to wrapper instead of exiting')
|
print('WARNING: Module returned to wrapper instead of exiting')
|
||||||
|
@ -257,6 +262,9 @@ if __name__ == '__main__':
|
||||||
if PY3:
|
if PY3:
|
||||||
ZIPLOADER_PARAMS = ZIPLOADER_PARAMS.encode('utf-8')
|
ZIPLOADER_PARAMS = ZIPLOADER_PARAMS.encode('utf-8')
|
||||||
try:
|
try:
|
||||||
|
# There's a race condition with the controller removing the
|
||||||
|
# remote_tmpdir and this module executing under async. So we cannot
|
||||||
|
# store this in remote_tmpdir (use system tempdir instead)
|
||||||
temp_path = tempfile.mkdtemp(prefix='ansible_')
|
temp_path = tempfile.mkdtemp(prefix='ansible_')
|
||||||
zipped_mod = os.path.join(temp_path, 'ansible_modlib.zip')
|
zipped_mod = os.path.join(temp_path, 'ansible_modlib.zip')
|
||||||
modlib = open(zipped_mod, 'wb')
|
modlib = open(zipped_mod, 'wb')
|
||||||
|
|
Loading…
Add table
Reference in a new issue