From: Alex Willmer <alex@moreati.org.uk>
Date: Mon, 12 Sep 2022 14:11:00 +0200
Subject: Ansible 6 support

fixes #929

Bug-Upstream: https://github.com/mitogen-hq/mitogen/issues/929
Bug-Debian: https://bugs.debian.org/1019501
Origin: upstream, https://github.com/mitogen-hq/mitogen/pull/933
---
 .ci/azure-pipelines.yml    | 60 +++-------------------------------------------
 ansible_mitogen/loaders.py |  2 +-
 docs/ansible_detailed.rst  |  2 +-
 mitogen/master.py          |  2 +-
 tox.ini                    | 18 +++++++-------
 5 files changed, 14 insertions(+), 70 deletions(-)

diff --git a/.ci/azure-pipelines.yml b/.ci/azure-pipelines.yml
index 6f45397..98f4805 100644
--- a/.ci/azure-pipelines.yml
+++ b/.ci/azure-pipelines.yml
@@ -33,9 +33,6 @@ jobs:
       Loc_27_210:
         python.version: '2.7'
         tox.env: py27-mode_localhost-ansible2.10
-      Loc_27_3:
-        python.version: '2.7'
-        tox.env: py27-mode_localhost-ansible3
       Loc_27_4:
         python.version: '2.7'
         tox.env: py27-mode_localhost-ansible4
@@ -46,11 +43,6 @@ jobs:
         tox.env: py27-mode_localhost-ansible2.10
         STRATEGY: linear
         ANSIBLE_SKIP_TAGS: resource_intensive
-      Van_27_3:
-        python.version: '2.7'
-        tox.env: py27-mode_localhost-ansible3
-        STRATEGY: linear
-        ANSIBLE_SKIP_TAGS: resource_intensive
       Van_27_4:
         python.version: '2.7'
         tox.env: py27-mode_localhost-ansible4
@@ -79,8 +71,6 @@ jobs:
       # TODO: test python3, python3 tests are broken
       Loc_27_210:
         tox.env: py27-mode_localhost-ansible2.10
-      Loc_27_3:
-        tox.env: py27-mode_localhost-ansible3
       Loc_27_4:
         tox.env: py27-mode_localhost-ansible4
 
@@ -89,10 +79,6 @@ jobs:
         tox.env: py27-mode_localhost-ansible2.10
         STRATEGY: linear
         ANSIBLE_SKIP_TAGS: resource_intensive
-      Van_27_3:
-        tox.env: py27-mode_localhost-ansible3
-        STRATEGY: linear
-        ANSIBLE_SKIP_TAGS: resource_intensive
       Van_27_4:
         tox.env: py27-mode_localhost-ansible4
         STRATEGY: linear
@@ -190,49 +176,9 @@ jobs:
         python.version: '3.10'
         tox.env: py310-mode_mitogen-distro_ubuntu2004
 
-      #DebOps_2460_27_27:
-        #python.version: '2.7'
-        #MODE: debops_common
-        #VER: 2.4.6.0
-
-      #DebOps_262_36_27:
-        #python.version: '3.6'
-        #MODE: debops_common
-        #VER: 2.6.2
-
-      #Ansible_2460_26:
-        #python.version: '2.7'
-        #MODE: ansible
-        #VER: 2.4.6.0
-
-      #Ansible_262_26:
-        #python.version: '2.7'
-        #MODE: ansible
-        #VER: 2.6.2
-
-      #Ansible_2460_36:
-        #python.version: '3.6'
-        #MODE: ansible
-        #VER: 2.4.6.0
-
-      #Ansible_262_36:
-        #python.version: '3.6'
-        #MODE: ansible
-        #VER: 2.6.2
-
-      #Vanilla_262_27:
-        #python.version: '2.7'
-        #MODE: ansible
-        #VER: 2.6.2
-        #DISTROS: debian
-        #STRATEGY: linear
-
       Ans_27_210:
         python.version: '2.7'
         tox.env: py27-mode_ansible-ansible2.10
-      Ans_27_3:
-        python.version: '2.7'
-        tox.env: py27-mode_ansible-ansible3
       Ans_27_4:
         python.version: '2.7'
         tox.env: py27-mode_ansible-ansible4
@@ -240,9 +186,6 @@ jobs:
       Ans_36_210:
         python.version: '3.6'
         tox.env: py36-mode_ansible-ansible2.10
-      Ans_36_3:
-        python.version: '3.6'
-        tox.env: py36-mode_ansible-ansible3
       Ans_36_4:
         python.version: '3.6'
         tox.env: py36-mode_ansible-ansible4
@@ -259,3 +202,6 @@ jobs:
       Ans_310_5:
         python.version: '3.10'
         tox.env: py310-mode_ansible-ansible5
+      Ans_310_6:
+        python.version: '3.10'
+        tox.env: py310-mode_ansible-ansible6
diff --git a/ansible_mitogen/loaders.py b/ansible_mitogen/loaders.py
index cd05fea..20aa499 100644
--- a/ansible_mitogen/loaders.py
+++ b/ansible_mitogen/loaders.py
@@ -48,7 +48,7 @@ __all__ = [
 
 
 ANSIBLE_VERSION_MIN = (2, 10)
-ANSIBLE_VERSION_MAX = (2, 12)
+ANSIBLE_VERSION_MAX = (2, 14)
 
 NEW_VERSION_MSG = (
     "Your Ansible version (%s) is too recent. The most recent version\n"
diff --git a/docs/ansible_detailed.rst b/docs/ansible_detailed.rst
index d329807..dd569a7 100644
--- a/docs/ansible_detailed.rst
+++ b/docs/ansible_detailed.rst
@@ -148,7 +148,7 @@ Noteworthy Differences
 * Mitogen 0.2.x supports Ansible 2.3-2.9; with Python 2.6, 2.7, or 3.6.
   Mitogen 0.3.1+ supports
     - Ansible 2.10, 3, and 4; with Python 2.7, or 3.6-3.10
-    - Ansible 5; with Python 3.8-3.10
+    - Ansible 5 and 6; with Python 3.8-3.10
   Verify your installation is running one of these versions by checking
   ``ansible --version`` output.
 
diff --git a/mitogen/master.py b/mitogen/master.py
index 3a163a8..4fb535f 100644
--- a/mitogen/master.py
+++ b/mitogen/master.py
@@ -536,7 +536,7 @@ class PkgutilMethod(FinderMethod):
 
         try:
             path = loader.get_filename(fullname)
-        except (AttributeError, ImportError):
+        except (AttributeError, ImportError, ValueError):
             # - get_filename() may throw ImportError if pkgutil.find_loader()
             #   picks a "parent" package's loader for some crap that's been
             #   stuffed in sys.modules, for example in the case of urllib3:
diff --git a/tox.ini b/tox.ini
index 6b2addc..5b01516 100644
--- a/tox.ini
+++ b/tox.ini
@@ -26,6 +26,7 @@
 # ansible == 3.*     ansible-base ~= 2.10.0
 # ansible == 4.*     ansible-core ~= 2.11.0
 # ansible == 5.*     ansible-core ~= 2.12.0
+# ansible == 6.*     ansible-core ~= 2.13.0
 
 # pip --no-python-version-warning
 # pip --disable-pip-version-check
@@ -36,7 +37,7 @@
 envlist =
     init,
     py{27,36}-mode_ansible-ansible{2.10,3,4},
-    py{310}-mode_ansible-ansible{2.10,3,4,5},
+    py{310}-mode_ansible-ansible{2.10,3,4,5,6},
     py{27,36,310}-mode_mitogen-distro_centos{6,7,8},
     py{27,36,310}-mode_mitogen-distro_debian{9,10,11},
     py{27,36,310}-mode_mitogen-distro_ubuntu{1604,1804,2004},
@@ -57,16 +58,11 @@ basepython =
 deps =
     -r{toxinidir}/tests/requirements.txt
     mode_ansible: -r{toxinidir}/tests/ansible/requirements.txt
-    ansible2.3: ansible==2.3.3.0
-    ansible2.4: ansible==2.4.6.0
-    ansible2.8: ansible==2.8.3
-    ansible2.9: ansible==2.9.6
-    ansible2.10: ansible-base<2.10.14
-    ansible2.10: ansible==2.10.0
-    ansible3: ansible-base<2.10.14
+    ansible2.10: ansible==2.10.7
     ansible3: ansible==3.4.0
-    ansible4: ansible==4.8.0
-    ansible5: ansible==5.0.1
+    ansible4: ansible==4.10.0
+    ansible5: ansible==5.8.0
+    ansible6: ansible==6.0.0
 install_command =
     python -m pip --no-python-version-warning --disable-pip-version-check install {opts} {packages}
 commands_pre =
@@ -102,6 +98,8 @@ setenv =
     distro_ubuntu1804: DISTRO=ubuntu1804
     distro_ubuntu2004: DISTRO=ubuntu2004
     # Note the plural, only applicable to MODE=ansible
+    # Ansible 6 (ansible-core 2.13) requires Python >= 2.7 or >= 3.5 on targets
+    ansible6: DISTROS=centos7 centos8 debian9 debian10 debian11 ubuntu1604 ubuntu1804 ubuntu2004
     distros_centos: DISTROS=centos6 centos7 centos8
     distros_centos5: DISTROS=centos5
     distros_centos6: DISTROS=centos6
