ansible_mitogen: Remove fallback imports for Ansible < 2.10

pull/1127/head
Alex Willmer 2 months ago
parent b1fd6038bf
commit 0a908d76da

@ -32,15 +32,13 @@ __metaclass__ = type
import logging import logging
import os import os
import ansible.utils.display
import mitogen.core import mitogen.core
import mitogen.utils import mitogen.utils
try:
from __main__ import display
except ImportError:
import ansible.utils.display
display = ansible.utils.display.Display()
display = ansible.utils.display.Display()
#: The process name set via :func:`set_process_name`. #: The process name set via :func:`set_process_name`.
_process_name = None _process_name = None

@ -40,13 +40,15 @@ try:
except ImportError: except ImportError:
from pipes import quote as shlex_quote from pipes import quote as shlex_quote
from ansible.module_utils._text import to_bytes
from ansible.parsing.utils.jsonify import jsonify
import ansible import ansible
import ansible.constants import ansible.constants
import ansible.plugins import ansible.plugins
import ansible.plugins.action import ansible.plugins.action
import ansible.utils.unsafe_proxy
import ansible.vars.clean
from ansible.module_utils.common.text.converters import to_bytes, to_text
from ansible.parsing.utils.jsonify import jsonify
import mitogen.core import mitogen.core
import mitogen.select import mitogen.select
@ -57,24 +59,6 @@ import ansible_mitogen.target
import ansible_mitogen.utils import ansible_mitogen.utils
import ansible_mitogen.utils.unsafe import ansible_mitogen.utils.unsafe
from ansible.module_utils._text import to_text
try:
from ansible.utils.unsafe_proxy import wrap_var
except ImportError:
from ansible.vars.unsafe_proxy import wrap_var
try:
# ansible 2.8 moved remove_internal_keys to the clean module
from ansible.vars.clean import remove_internal_keys
except ImportError:
try:
from ansible.vars.manager import remove_internal_keys
except ImportError:
# ansible 2.3.3 has remove_internal_keys as a protected func on the action class
# we'll fallback to calling self._remove_internal_keys in this case
remove_internal_keys = lambda a: "Not found"
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -413,10 +397,7 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase):
self._remove_tmp_path(tmp) self._remove_tmp_path(tmp)
# prevents things like discovered_interpreter_* or ansible_discovered_interpreter_* from being set # prevents things like discovered_interpreter_* or ansible_discovered_interpreter_* from being set
# handle ansible 2.3.3 that has remove_internal_keys in a different place ansible.vars.clean.remove_internal_keys(result)
check = remove_internal_keys(result)
if check == 'Not found':
self._remove_internal_keys(result)
# taken from _execute_module of ansible 2.8.6 # taken from _execute_module of ansible 2.8.6
# propagate interpreter discovery results back to the controller # propagate interpreter discovery results back to the controller
@ -440,7 +421,7 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase):
result['deprecations'] = [] result['deprecations'] = []
result['deprecations'].extend(self._discovery_deprecation_warnings) result['deprecations'].extend(self._discovery_deprecation_warnings)
return wrap_var(result) return ansible.utils.unsafe_proxy.wrap_var(result)
def _postprocess_response(self, result): def _postprocess_response(self, result):
""" """

@ -65,21 +65,12 @@ import abc
import os import os
import ansible.utils.shlex import ansible.utils.shlex
import ansible.constants as C import ansible.constants as C
import ansible.executor.interpreter_discovery
import ansible.utils.unsafe_proxy
from ansible.module_utils.six import with_metaclass from ansible.module_utils.six import with_metaclass
from ansible.module_utils.parsing.convert_bool import boolean from ansible.module_utils.parsing.convert_bool import boolean
# this was added in Ansible >= 2.8.0; fallback to the default interpreter if necessary
try:
from ansible.executor.interpreter_discovery import discover_interpreter
except ImportError:
discover_interpreter = lambda action,interpreter_name,discovery_mode,task_vars: '/usr/bin/python'
try:
from ansible.utils.unsafe_proxy import AnsibleUnsafeText
except ImportError:
from ansible.vars.unsafe_proxy import AnsibleUnsafeText
import mitogen.core import mitogen.core
@ -115,12 +106,13 @@ def run_interpreter_discovery_if_necessary(s, task_vars, action, rediscover_pyth
action._finding_python_interpreter = True action._finding_python_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 = AnsibleUnsafeText(discover_interpreter( s = ansible.executor.interpreter_discovery.discover_interpreter(
action=action, action=action,
interpreter_name=interpreter_name, interpreter_name=interpreter_name,
discovery_mode=s, discovery_mode=s,
task_vars=task_vars)) task_vars=task_vars,
)
s = ansible.utils.unsafe_proxy.AnsibleUnsafeText(s)
# cache discovered interpreter # cache discovered interpreter
task_vars['ansible_facts'][discovered_interpreter_config] = s task_vars['ansible_facts'][discovered_interpreter_config] = s
action._connection.has_pipelining = False action._connection.has_pipelining = False

@ -25,6 +25,8 @@ Unreleased
fallbacks and polyfills into :mod:`mitogen.core` fallbacks and polyfills into :mod:`mitogen.core`
* :gh:issue:`1127` :mod:`ansible_mitogen`: Remove backward compatibility * :gh:issue:`1127` :mod:`ansible_mitogen`: Remove backward compatibility
fallbacks for Python 2.4 & 2.5. fallbacks for Python 2.4 & 2.5.
* :gh:issue:`1127` :mod:`ansible_mitogen`: Remove fallback imports for Ansible
releases before 2.10
v0.3.10 (2024-09-20) v0.3.10 (2024-09-20)

Loading…
Cancel
Save