From a731be32a2ae92c590bf914d605c7f98c14ecbf3 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 2 Apr 2018 10:37:23 +0100 Subject: [PATCH] ansible: use _ansible_shell_executable in ScriptRunner. Now we match Ansible error output and exit status. Ansible: $ ansible localhost -e end=2 -m custom_binary_single_null localhost | FAILED! => { "changed": false, "module_stderr": "Shared connection to localhost closed.\r\n", "module_stdout": "/bin/sh: /Users/dmw/.ansible/tmp/ansible-tmp-1522661797.42-158833651208060/custom_binary_single_null: cannot execute binary file\r\n", "msg": "MODULE FAILURE", "rc": 126 } Mitogen now: localhost | FAILED! => { "changed": false, "module_stderr": "/bin/sh: /var/folders/gw/f6w3dgy16fsg5y4kdthbqycw0000gn/T/ansible_mitogenAYF8LM-binary: cannot execute binary file\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 126 } Previously: localhost | FAILED! => { "changed": false, "module_stderr": ": [Errno 8] Exec format error", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1 } --- ansible_mitogen/runner.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ansible_mitogen/runner.py b/ansible_mitogen/runner.py index c9ab8427..6cfa4166 100644 --- a/ansible_mitogen/runner.py +++ b/ansible_mitogen/runner.py @@ -214,7 +214,11 @@ class ProgramRunner(Runner): ) def _get_program_args(self): - return [self.program_fp.name] + return [ + self.args['_ansible_shell_executable'], + '-c', + self.program_fp.name + ] def revert(self): """ @@ -229,6 +233,7 @@ class ProgramRunner(Runner): args=self._get_program_args(), ) except Exception, e: + LOG.exception('While running %s', self._get_program_args()) return { 'rc': 1, 'stdout': '', @@ -267,7 +272,11 @@ class ArgsFileRunner(Runner): return json.dumps(self.args) def _get_program_args(self): - return [self.program_fp.name, self.args_fp.name] + return [ + self.args['_ansible_shell_executable'], + '-c', + "%s %s" % (self.program_fp.name, self.args_fp.name), + ] def revert(self): """