summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Clay <matt@mystile.com>2016-11-22 16:47:46 -0800
committerGitHub <noreply@github.com>2016-11-22 16:47:46 -0800
commitb598611afb2f7615177fc8bf4353e077e57e7b51 (patch)
tree4a347c7832795efbd66da45149daaf1045ab3522
parentff9bf54891945b90d1a1008274774b6eeeb06bf2 (diff)
downloadansible-modules-core-b598611afb2f7615177fc8bf4353e077e57e7b51.tar.gz
Support script interpreters in async_wrapper. (#5703)
-rw-r--r--utilities/logic/async_wrapper.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/utilities/logic/async_wrapper.py b/utilities/logic/async_wrapper.py
index 0d8c41ac..c58b8ee5 100644
--- a/utilities/logic/async_wrapper.py
+++ b/utilities/logic/async_wrapper.py
@@ -115,6 +115,18 @@ def _filter_non_json_lines(data):
return ('\n'.join(lines), warnings)
+
+def _get_interpreter(module_path):
+ module_fd = open(module_path, 'rb')
+ try:
+ head = module_fd.read(1024)
+ if head[0:2] != '#!':
+ return None
+ return head[2:head.index('\n')].strip().split(' ')
+ finally:
+ module_fd.close()
+
+
def _run_module(wrapped_cmd, jid, job_path):
tmp_job_path = job_path + ".tmp"
@@ -130,6 +142,11 @@ def _run_module(wrapped_cmd, jid, job_path):
stderr = ''
try:
cmd = shlex.split(wrapped_cmd)
+ # call the module interpreter directly (for non-binary modules)
+ # this permits use of a script for an interpreter on non-Linux platforms
+ interpreter = _get_interpreter(cmd[0])
+ if interpreter:
+ cmd = interpreter + cmd
script = subprocess.Popen(cmd, shell=False, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(outdata, stderr) = script.communicate()
if PY3: