ansible_mitogen: Rename Mitogen interpreter discovery attributes
This makes their nature and ownership/responsibility much more explicit.
This commit is contained in:
parent
d3da3ff769
commit
1b8b2c8b1a
|
@ -103,8 +103,10 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase):
|
||||||
|
|
||||||
# required for python interpreter discovery
|
# required for python interpreter discovery
|
||||||
connection.templar = self._templar
|
connection.templar = self._templar
|
||||||
self._finding_python_interpreter = False
|
|
||||||
self._rediscovered_python = False
|
self._mitogen_discovering_interpreter = False
|
||||||
|
self._mitogen_interpreter_candidate = None
|
||||||
|
self._mitogen_rediscovered_interpreter = False
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
def run(self, tmp=None, task_vars=None):
|
||||||
"""
|
"""
|
||||||
|
@ -397,7 +399,7 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase):
|
||||||
# only cache discovered_interpreter if we're not running a rediscovery
|
# only cache discovered_interpreter if we're not running a rediscovery
|
||||||
# rediscovery happens in places like docker connections that could have different
|
# rediscovery happens in places like docker connections that could have different
|
||||||
# python interpreters than the main host
|
# python interpreters than the main host
|
||||||
if not self._rediscovered_python:
|
if not self._mitogen_rediscovered_interpreter:
|
||||||
result['ansible_facts'][self._discovered_interpreter_key] = self._discovered_interpreter
|
result['ansible_facts'][self._discovered_interpreter_key] = self._discovered_interpreter
|
||||||
|
|
||||||
if self._discovery_warnings:
|
if self._discovery_warnings:
|
||||||
|
@ -457,7 +459,7 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase):
|
||||||
# calling exec_command until we run into the right python we'll use
|
# calling exec_command until we run into the right python we'll use
|
||||||
# chicken-and-egg issue, mitogen needs a python to run low_level_execute_command
|
# chicken-and-egg issue, mitogen needs a python to run low_level_execute_command
|
||||||
# which is required by Ansible's discover_interpreter function
|
# which is required by Ansible's discover_interpreter function
|
||||||
if self._finding_python_interpreter:
|
if self._mitogen_discovering_interpreter:
|
||||||
possible_pythons = [
|
possible_pythons = [
|
||||||
'/usr/bin/python',
|
'/usr/bin/python',
|
||||||
'python3',
|
'python3',
|
||||||
|
@ -484,7 +486,7 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase):
|
||||||
|
|
||||||
for possible_python in possible_pythons:
|
for possible_python in possible_pythons:
|
||||||
try:
|
try:
|
||||||
self._possible_python_interpreter = possible_python
|
self._mitogen_interpreter_candidate = possible_python
|
||||||
rc, stdout, stderr = _run_cmd()
|
rc, stdout, stderr = _run_cmd()
|
||||||
# TODO: what exception is thrown?
|
# TODO: what exception is thrown?
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -87,8 +87,8 @@ def run_interpreter_discovery_if_necessary(s, task_vars, action, rediscover_pyth
|
||||||
it could be different than what's ran on the host
|
it could be different than what's ran on the host
|
||||||
"""
|
"""
|
||||||
# keep trying different interpreters until we don't error
|
# keep trying different interpreters until we don't error
|
||||||
if action._finding_python_interpreter:
|
if action._mitogen_discovering_interpreter:
|
||||||
return action._possible_python_interpreter
|
return action._mitogen_interpreter_candidate
|
||||||
|
|
||||||
if s in ['auto', 'auto_legacy', 'auto_silent', 'auto_legacy_silent']:
|
if s in ['auto', 'auto_legacy', 'auto_silent', 'auto_legacy_silent']:
|
||||||
# python is the only supported interpreter_name as of Ansible 2.8.8
|
# python is the only supported interpreter_name as of Ansible 2.8.8
|
||||||
|
@ -102,13 +102,13 @@ def run_interpreter_discovery_if_necessary(s, task_vars, action, rediscover_pyth
|
||||||
# if we're rediscovering python then chances are we're running something like a docker connection
|
# if we're rediscovering python then chances are we're running something like a docker connection
|
||||||
# this will handle scenarios like running a playbook that does stuff + then dynamically creates a docker container,
|
# this will handle scenarios like running a playbook that does stuff + then dynamically creates a docker container,
|
||||||
# then runs the rest of the playbook inside that container, and then rerunning the playbook again
|
# then runs the rest of the playbook inside that container, and then rerunning the playbook again
|
||||||
action._rediscovered_python = True
|
action._mitogen_rediscovered_interpreter = True
|
||||||
|
|
||||||
# blow away the discovered_interpreter_config cache and rediscover
|
# blow away the discovered_interpreter_config cache and rediscover
|
||||||
del task_vars['ansible_facts'][discovered_interpreter_config]
|
del task_vars['ansible_facts'][discovered_interpreter_config]
|
||||||
|
|
||||||
if discovered_interpreter_config not in task_vars['ansible_facts']:
|
if discovered_interpreter_config not in task_vars['ansible_facts']:
|
||||||
action._finding_python_interpreter = True
|
action._mitogen_discovering_interpreter = True
|
||||||
# fake pipelining so discover_interpreter can be happy
|
# fake pipelining so discover_interpreter can be happy
|
||||||
action._connection.has_pipelining = True
|
action._connection.has_pipelining = True
|
||||||
s = ansible.executor.interpreter_discovery.discover_interpreter(
|
s = ansible.executor.interpreter_discovery.discover_interpreter(
|
||||||
|
@ -128,7 +128,7 @@ def run_interpreter_discovery_if_necessary(s, task_vars, action, rediscover_pyth
|
||||||
action._discovered_interpreter_key = discovered_interpreter_config
|
action._discovered_interpreter_key = discovered_interpreter_config
|
||||||
action._discovered_interpreter = s
|
action._discovered_interpreter = s
|
||||||
|
|
||||||
action._finding_python_interpreter = False
|
action._mitogen_discovering_interpreter = False
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,8 @@ In progress (unreleased)
|
||||||
* :gh:issue:`1213` tests: Fix unclosed file in fd_check script
|
* :gh:issue:`1213` tests: Fix unclosed file in fd_check script
|
||||||
* :gh:issue:`1213` :mod:`ansible_mitogen`: Don't redeclare Ansible interpreter
|
* :gh:issue:`1213` :mod:`ansible_mitogen`: Don't redeclare Ansible interpreter
|
||||||
discovery attributes
|
discovery attributes
|
||||||
|
* :gh:issue:`1213` :mod:`ansible_mitogen`: Rename Mitogen interpreter discovery
|
||||||
|
attributes
|
||||||
|
|
||||||
|
|
||||||
v0.3.21 (2025-01-20)
|
v0.3.21 (2025-01-20)
|
||||||
|
|
|
@ -45,7 +45,9 @@ class ConnectionMixin(MuxProcessMixin):
|
||||||
conn = self.klass(play_context, new_stdin=False)
|
conn = self.klass(play_context, new_stdin=False)
|
||||||
# conn functions don't fetch ActionModuleMixin objs from _get_task_vars()
|
# conn functions don't fetch ActionModuleMixin objs from _get_task_vars()
|
||||||
# through the usual walk-the-stack approach so we'll not run interpreter discovery here
|
# through the usual walk-the-stack approach so we'll not run interpreter discovery here
|
||||||
conn._action = mock.MagicMock(_possible_python_interpreter=testlib.base_executable())
|
conn._action = mock.MagicMock(
|
||||||
|
_mitogen_interpreter_candidate=testlib.base_executable(),
|
||||||
|
)
|
||||||
conn.on_action_run(
|
conn.on_action_run(
|
||||||
task_vars={},
|
task_vars={},
|
||||||
delegate_to_hostname=None,
|
delegate_to_hostname=None,
|
||||||
|
|
Loading…
Reference in New Issue