Skip to content

Commit

Permalink
Merge pull request #933 from moreati/ansible6
Browse files Browse the repository at this point in the history
Ansible 6 support
  • Loading branch information
moreati authored Jul 24, 2022
2 parents e36bbde + f150387 commit 8cda5f5
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 79 deletions.
60 changes: 3 additions & 57 deletions .ci/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -190,59 +176,16 @@ 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

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
Expand All @@ -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
4 changes: 3 additions & 1 deletion ansible_mitogen/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

__all__ = [
'action_loader',
'become_loader',
'connection_loader',
'module_loader',
'module_utils_loader',
Expand All @@ -48,7 +49,7 @@


ANSIBLE_VERSION_MIN = (2, 10)
ANSIBLE_VERSION_MAX = (2, 12)
ANSIBLE_VERSION_MAX = (2, 13)

NEW_VERSION_MSG = (
"Your Ansible version (%s) is too recent. The most recent version\n"
Expand Down Expand Up @@ -90,6 +91,7 @@ def assert_supported_release():


from ansible.plugins.loader import action_loader
from ansible.plugins.loader import become_loader
from ansible.plugins.loader import connection_loader
from ansible.plugins.loader import module_loader
from ansible.plugins.loader import module_utils_loader
Expand Down
10 changes: 7 additions & 3 deletions ansible_mitogen/transport_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
except ImportError:
from ansible.vars.unsafe_proxy import AnsibleUnsafeText

import ansible_mitogen.loaders
import mitogen.core


Expand Down Expand Up @@ -435,7 +436,10 @@ def become_user(self):
return self._play_context.become_user

def become_pass(self):
return optional_secret(self._play_context.become_pass)
become_method = self.become_method()
become_plugin = ansible_mitogen.loaders.become_loader.get(become_method)
become_pass = become_plugin.get_option('become_pass', hostvars=self._task_vars)
return optional_secret(become_pass)

def password(self):
return optional_secret(self._play_context.password)
Expand Down Expand Up @@ -652,8 +656,8 @@ def become_user(self):

def become_pass(self):
return optional_secret(
self._host_vars.get('ansible_become_password') or
self._host_vars.get('ansible_become_pass')
self._host_vars.get('ansible_become_pass') or
self._host_vars.get('ansible_become_password')
)

def password(self):
Expand Down
2 changes: 1 addition & 1 deletion docs/ansible_detailed.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ To avail of fixes in an unreleased version, please download a ZIP file
v0.3.4.dev0
-------------------

* :gh:issue:`929` Support Ansible 6 and ansible-core 2.13
* :gh:issue:`832` Fix runtime error when using the ansible.builtin.dnf module multiple times

v0.3.3 (2022-06-03)
Expand Down
2 changes: 1 addition & 1 deletion mitogen/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ def find(self, fullname):

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:
Expand Down
2 changes: 1 addition & 1 deletion tests/ansible/hosts/transport_config.hosts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ tc-become-user-set ansible_become_user=ansi-become-user
tc-become-pass-unset
tc-become-pass-password ansible_become_password=apassword
tc-become-pass-pass ansible_become_pass=apass
tc-become-pass-both ansible_become_password=a.b.c ansible_become_pass=c.b.a
tc-become-pass-both ansible_become_pass=bpass ansible_become_password=bpassword

# port()
tc-port-unset
Expand Down
9 changes: 4 additions & 5 deletions tests/ansible/integration/transport_config/become_pass.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@
fail_msg: out={{out}}



# ansible_become_pass & ansible_become_password set, password used to take precedence
# but it's possible since https://github.com/ansible/ansible/pull/69629/files#r428376864, now it doesn't
- hosts: tc-become-pass-both
become: true
tasks:
Expand All @@ -132,7 +129,9 @@
- out.result|length == 2
- out.result[0].method == "ssh"
- out.result[1].method == "sudo"
- out.result[1].kwargs.password == "c.b.a"
# Ansible >= 2.10 builtin become plugins (e.g. sudo, su) give priority
# to ansible_become_pass over ansible_become_password.
- out.result[1].kwargs.password == "bpass"
fail_msg: out={{out}}


Expand All @@ -147,6 +146,6 @@
- out.result|length == 3
- out.result[0].method == "ssh"
- out.result[1].method == "sudo"
- out.result[1].kwargs.password == "a.b.c"
- out.result[1].kwargs.password == "bpass"
- out.result[2].method == "ssh"
fail_msg: out={{out}}
18 changes: 8 additions & 10 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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},
Expand All @@ -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 =
Expand Down Expand Up @@ -103,6 +99,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
Expand Down

0 comments on commit 8cda5f5

Please sign in to comment.