From 822502125d3653d8d63c60f1a24defa26d2fb1cd Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sun, 1 Apr 2018 22:04:05 +0100 Subject: [PATCH] issue #106: 2.3.x compatible get_shebang-alike. --- ansible_mitogen/planner.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/ansible_mitogen/planner.py b/ansible_mitogen/planner.py index e7b553c6..49c0be06 100644 --- a/ansible_mitogen/planner.py +++ b/ansible_mitogen/planner.py @@ -166,20 +166,24 @@ class ScriptPlanner(BinaryPlanner): Common functionality for script module planners -- handle interpreter detection and rewrite. """ + def _rewrite_interpreter(self, interpreter, task_vars, templar): + key = u'ansible_%s_interpreter' % os.path.basename(interpreter).strip() + try: + return templar.template(task_vars[key].strip()) + except KeyError: + return interpreter + def plan(self, invocation): kwargs = super(ScriptPlanner, self).plan(invocation) interpreter, arg = parse_script_interpreter(invocation.module_source) - shebang, _ = module_common._get_shebang( - interpreter=interpreter, - task_vars=invocation.task_vars, - templar=invocation.templar, + return dict(kwargs, + interpreter_arg=arg, + interpreter=self._rewrite_interpreter( + interpreter=interpreter, + task_vars=invocation.task_vars, + templar=invocation.templar, + ) ) - if shebang: - interpreter = shebang[2:] - - kwargs['interpreter'] = interpreter - kwargs['interpreter_arg'] = arg - return kwargs class ReplacerPlanner(BinaryPlanner):