|
|
@ -216,9 +216,12 @@ class ScriptPlanner(BinaryPlanner):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
def _rewrite_interpreter(self, path):
|
|
|
|
def _rewrite_interpreter(self, path):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Given the original interpreter binary extracted from the script's
|
|
|
|
Given the interpreter path (from the script's hashbang line), return
|
|
|
|
interpreter line, look up the associated `ansible_*_interpreter`
|
|
|
|
the desired interpreter path. This tries, in order
|
|
|
|
variable, render it and return it.
|
|
|
|
|
|
|
|
|
|
|
|
1. Look up & render the `ansible_*_interpreter` variable, if set
|
|
|
|
|
|
|
|
2. Look up the `discovered_interpreter_*` fact, if present
|
|
|
|
|
|
|
|
3. The unmodified path from the hashbang line.
|
|
|
|
|
|
|
|
|
|
|
|
:param str path:
|
|
|
|
:param str path:
|
|
|
|
Absolute path to original interpreter (e.g. '/usr/bin/python').
|
|
|
|
Absolute path to original interpreter (e.g. '/usr/bin/python').
|
|
|
@ -229,7 +232,8 @@ class ScriptPlanner(BinaryPlanner):
|
|
|
|
involved here, the vanilla implementation uses it and that use is
|
|
|
|
involved here, the vanilla implementation uses it and that use is
|
|
|
|
exploited in common playbooks.
|
|
|
|
exploited in common playbooks.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
key = u'ansible_%s_interpreter' % os.path.basename(path).strip()
|
|
|
|
interpreter_name = os.path.basename(path).strip()
|
|
|
|
|
|
|
|
key = u'ansible_%s_interpreter' % interpreter_name
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
template = self._inv.task_vars[key]
|
|
|
|
template = self._inv.task_vars[key]
|
|
|
|
except KeyError:
|
|
|
|
except KeyError:
|
|
|
@ -238,6 +242,14 @@ class ScriptPlanner(BinaryPlanner):
|
|
|
|
configured_interpreter = self._inv.templar.template(template)
|
|
|
|
configured_interpreter = self._inv.templar.template(template)
|
|
|
|
return ansible_mitogen.utils.unsafe.cast(configured_interpreter)
|
|
|
|
return ansible_mitogen.utils.unsafe.cast(configured_interpreter)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
key = u'discovered_interpreter_%s' % interpreter_name
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
discovered_interpreter = self._inv.task_vars['ansible_facts'][key]
|
|
|
|
|
|
|
|
except KeyError:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return ansible_mitogen.utils.unsafe.cast(discovered_interpreter)
|
|
|
|
|
|
|
|
|
|
|
|
return path
|
|
|
|
return path
|
|
|
|
|
|
|
|
|
|
|
|
def _get_interpreter(self):
|
|
|
|
def _get_interpreter(self):
|
|
|
@ -253,7 +265,8 @@ class ScriptPlanner(BinaryPlanner):
|
|
|
|
if arg:
|
|
|
|
if arg:
|
|
|
|
fragment += ' ' + arg
|
|
|
|
fragment += ' ' + arg
|
|
|
|
|
|
|
|
|
|
|
|
return fragment, path.startswith('python')
|
|
|
|
is_python = path.startswith('python')
|
|
|
|
|
|
|
|
return fragment, is_python
|
|
|
|
|
|
|
|
|
|
|
|
def get_kwargs(self, **kwargs):
|
|
|
|
def get_kwargs(self, **kwargs):
|
|
|
|
interpreter_fragment, is_python = self._get_interpreter()
|
|
|
|
interpreter_fragment, is_python = self._get_interpreter()
|
|
|
|