From fe9bf1d81ddfa2beeee5a2296ecefc67c1ac4506 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 2 Apr 2018 08:08:14 +0000 Subject: [PATCH] ansible: match Ansible behaviour when script lacks interpreter line. --- ansible_mitogen/planner.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ansible_mitogen/planner.py b/ansible_mitogen/planner.py index b940fbbb..11531e4a 100644 --- a/ansible_mitogen/planner.py +++ b/ansible_mitogen/planner.py @@ -184,25 +184,27 @@ class ScriptPlanner(BinaryPlanner): Common functionality for script module planners -- handle interpreter detection and rewrite. """ - def _rewrite_interpreter(self, interpreter, task_vars, templar): - if interpreter is None: - return None - + def _rewrite_interpreter(self, invocation, interpreter): key = u'ansible_%s_interpreter' % os.path.basename(interpreter).strip() try: - return templar.template(task_vars[key].strip()) + template = invocation.task_vars[key].strip() + return invocation.templar.template(template) except KeyError: return interpreter def plan(self, invocation): kwargs = super(ScriptPlanner, self).plan(invocation) interpreter, arg = parse_script_interpreter(invocation.module_source) + if interpreter is None: + raise ansible.errors.AnsibleError(NO_INTERPRETER_MSG % ( + invocation.module_name, + )) + return dict(kwargs, interpreter_arg=arg, interpreter=self._rewrite_interpreter( interpreter=interpreter, - task_vars=invocation.task_vars, - templar=invocation.templar, + invocation=invocation ) ) @@ -305,6 +307,7 @@ _planners = [ NO_METHOD_MSG = 'Mitogen: no invocation method found for: ' CRASHED_MSG = 'Mitogen: internal error: ' +NO_INTERPRETER_MSG = 'module (%s) is missing interpreter line' def get_module_data(name):