diff --git a/ansible_mitogen/plugins/connection/mitogen_kubectl.py b/ansible_mitogen/plugins/connection/mitogen_kubectl.py index 44d3b50a..7f99376d 100644 --- a/ansible_mitogen/plugins/connection/mitogen_kubectl.py +++ b/ansible_mitogen/plugins/connection/mitogen_kubectl.py @@ -45,17 +45,11 @@ import ansible_mitogen.connection import ansible_mitogen.loaders -_class = ansible_mitogen.loaders.connection_loader__get( +_get_result = ansible_mitogen.loaders.connection_loader__get( 'kubectl', class_only=True, ) -if _class: - kubectl = sys.modules[_class.__module__] - del _class -else: - kubectl = None - class Connection(ansible_mitogen.connection.Connection): transport = 'kubectl' @@ -66,13 +60,19 @@ class Connection(ansible_mitogen.connection.Connection): ) def __init__(self, *args, **kwargs): - if kubectl is None: + if not _get_result: raise AnsibleConnectionFailure(self.not_supported_msg) super(Connection, self).__init__(*args, **kwargs) def get_extra_args(self): + try: + # Ansible < 2.10, _get_result is the connection class + connection_options = _get_result.connection_options + except AttributeError: + # Ansible >= 2.10, _get_result is a get_with_context_result + connection_options = _get_result.object.connection_options parameters = [] - for key, option in iteritems(kubectl.CONNECTION_OPTIONS): + for key, option in iteritems(connection_options): if self.get_task_var('ansible_' + key) is not None: parameters += [ option, self.get_task_var('ansible_' + key) ] diff --git a/docs/changelog.rst b/docs/changelog.rst index da9d732c..787dd1c4 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -28,6 +28,7 @@ v0.3.1.dev0 (unreleased) * :gh:issue:`873` `python -c ...` first stage no longer uses :py:mod:`platform`` to detect the macOS release * :gh:issue:`876` `python -c ...` first stage no longer contains tab characters, to reduce size * :gh:issue:`878` Continuous Integration tests now correctly perform comparisons of 2 digit versions +* :gh:issue:`878` Kubectl connector fixed with Ansible 2.10 and above v0.3.0 (2021-11-24)