ansible: match Ansible behaviour when script lacks interpreter line.

This commit is contained in:
David Wilson 2018-04-02 08:08:14 +00:00
parent 1fab6d9c25
commit fe9bf1d81d
1 changed files with 10 additions and 7 deletions

View File

@ -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):