Skip to content

Commit 59e6fe5

Browse files
authored
Merge pull request #870 from moreati/ansible4
Support for Ansible 3 & 4
2 parents b5353aa + c61c063 commit 59e6fe5

File tree

14 files changed

+94
-100
lines changed

14 files changed

+94
-100
lines changed

.ci/azure-pipelines-steps.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ steps:
1313
- script: python -mpip install tox
1414
displayName: Install tooling
1515

16-
- script: tox -e $(tox.env)
16+
- script: tox -e "$(tox.env)"
1717
displayName: "Run tests"
1818
env:
1919
AWS_ACCESS_KEY_ID: $(AWS_ACCESS_KEY_ID)

.ci/azure-pipelines.yml

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ jobs:
2525
tox.env: py27-mode_mitogen
2626

2727
# TODO: test python3, python3 tests are broken
28-
Ans210_27:
28+
Local_Py27:
2929
python.version: '2.7'
30-
tox.env: py27-mode_localhost-ansible2.10
30+
tox.env: py27-mode_localhost-ansible{2.10,3,4}
3131

3232
# NOTE: this hangs when ran in Ubuntu 18.04
33-
Vanilla_210_27:
33+
Vanilla_Py27:
3434
python.version: '2.7'
35-
tox.env: py27-mode_localhost-ansible2.10
35+
tox.env: py27-mode_localhost-ansible{2.10,3,4}
3636
STRATEGY: linear
3737
ANSIBLE_SKIP_TAGS: resource_intensive
3838

@@ -45,22 +45,17 @@ jobs:
4545
- template: azure-pipelines-steps.yml
4646
strategy:
4747
matrix:
48-
Mito27Debian_27:
48+
Mito_Py27:
4949
python.version: '2.7'
50-
tox.env: py27-mode_mitogen-distro_debian9
50+
tox.env: py27-mode_mitogen-distro_{centos6,centos7,centos8,debian9,debian10,debian11,ubuntu1604,ubuntu1804,ubuntu2004}
5151

52-
Mito36CentOS6_26:
52+
Mito_Py36:
5353
python.version: '3.6'
54-
tox.env: py36-mode_mitogen-distro_centos6
54+
tox.env: py36-mode_mitogen-distro_{centos6,centos7,centos8,debian9,debian10,debian11,ubuntu1604,ubuntu1804,ubuntu2004}
5555

56-
Mito39Debian_27:
56+
Mito_Py39:
5757
python.version: '3.9'
58-
tox.env: py39-mode_mitogen-distro_debian9
59-
60-
#Py26CentOS7:
61-
#python.version: '2.7'
62-
#MODE: mitogen
63-
#DISTRO: centos6
58+
tox.env: py39-mode_mitogen-distro_{centos6,centos7,centos8,debian9,debian10,debian11,ubuntu1604,ubuntu1804,ubuntu2004}
6459

6560
#DebOps_2460_27_27:
6661
#python.version: '2.7'
@@ -99,14 +94,14 @@ jobs:
9994
#DISTROS: debian
10095
#STRATEGY: linear
10196

102-
Ansible_210_27:
97+
Ansible_Py27:
10398
python.version: '2.7'
104-
tox.env: py27-mode_ansible-ansible2.10
99+
tox.env: py27-mode_ansible-ansible{2.10,3,4}
105100

106-
Ansible_210_36:
101+
Ansible_Py36:
107102
python.version: '3.6'
108-
tox.env: py36-mode_ansible-ansible2.10
103+
tox.env: py36-mode_ansible-ansible{2.10,3,4}
109104

110-
Ansible_210_39:
105+
Ansible_Py39:
111106
python.version: '3.9'
112-
tox.env: py39-mode_ansible-ansible2.10
107+
tox.env: py39-mode_ansible-ansible{2.10,3,4}

.ci/ci_lib.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
)
2323
)
2424

25+
_print = print
26+
def print(*args, **kwargs):
27+
file = kwargs.get('file', sys.stdout)
28+
flush = kwargs.pop('flush', False)
29+
_print(*args, **kwargs)
30+
if flush:
31+
file.flush()
32+
2533

2634
#
2735
# check_output() monkeypatch cutpasted from testlib.py
@@ -71,24 +79,22 @@ def _argv(s, *args):
7179

7280

7381
def run(s, *args, **kwargs):
74-
""" Run a command, with arguments, and print timing information
82+
""" Run a command, with arguments
7583
7684
>>> rc = run('echo "%s %s"', 'foo', 'bar')
77-
Running: ['/usr/bin/time', '--', 'echo', 'foo bar']
85+
Running: ['echo', 'foo bar']
7886
foo bar
79-
0.00user 0.00system 0:00.00elapsed ?%CPU (0avgtext+0avgdata 1964maxresident)k
80-
0inputs+0outputs (0major+71minor)pagefaults 0swaps
81-
Finished running: ['/usr/bin/time', '--', 'echo', 'foo bar']
87+
Finished running: ['echo', 'foo bar']
8288
>>> rc
8389
0
8490
"""
85-
argv = ['/usr/bin/time', '--'] + _argv(s, *args)
86-
print('Running: %s' % (argv,))
91+
argv = _argv(s, *args)
92+
print('Running: %s' % (argv,), flush=True)
8793
try:
8894
ret = subprocess.check_call(argv, **kwargs)
89-
print('Finished running: %s' % (argv,))
95+
print('Finished running: %s' % (argv,), flush=True)
9096
except Exception:
91-
print('Exception occurred while running: %s' % (argv,))
97+
print('Exception occurred while running: %s' % (argv,), file=sys.stderr, flush=True)
9298
raise
9399

94100
return ret
@@ -155,7 +161,7 @@ def get_output(s, *args, **kwargs):
155161
'foo bar\n'
156162
"""
157163
argv = _argv(s, *args)
158-
print('Running: %s' % (argv,))
164+
print('Running: %s' % (argv,), flush=True)
159165
return subprocess.check_output(argv, **kwargs)
160166

161167

@@ -368,12 +374,10 @@ def start_containers(containers):
368374
def verify_procs(hostname, old, new):
369375
oldpids = set(pid for pid, _ in old)
370376
if any(pid not in oldpids for pid, _ in new):
371-
print('%r had stray processes running:' % (hostname,))
377+
print('%r had stray processes running:' % (hostname,), file=sys.stderr, flush=True)
372378
for pid, line in new:
373379
if pid not in oldpids:
374-
print('New process:', line)
375-
376-
print()
380+
print('New process:', line, flush=True)
377381
return False
378382

379383
return True
@@ -397,13 +401,10 @@ def check_stray_processes(old, containers=None):
397401

398402

399403
def dump_file(path):
400-
print()
401-
print('--- %s ---' % (path,))
402-
print()
404+
print('--- %s ---' % (path,), flush=True)
403405
with open(path, 'r') as fp:
404-
print(fp.read().rstrip())
405-
print('---')
406-
print()
406+
print(fp.read().rstrip(), flush=True)
407+
print('---', flush=True)
407408

408409

409410
# SSH passes these through to the container when run interactively, causing

.ci/debops_common_tests.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env python
22

3-
from __future__ import print_function
43
import os
5-
import shutil
64
import sys
75

86
import ci_lib
@@ -60,11 +58,7 @@
6058
for container in containers
6159
)
6260

63-
print()
64-
print(' echo --- ansible/inventory/hosts: ---')
65-
ci_lib.run('cat ansible/inventory/hosts')
66-
print('---')
67-
print()
61+
ci_lib.dump_file('ansible/inventory/hosts')
6862

6963
# Now we have real host key checking, we need to turn it off
7064
os.environ['ANSIBLE_HOST_KEY_CHECKING'] = 'False'

.ci/localhost_ansible_tests.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,19 @@
3333

3434
with ci_lib.Fold('machine_prep'):
3535
# generate a new ssh key for localhost ssh
36-
os.system("ssh-keygen -P '' -m pem -f ~/.ssh/id_rsa")
37-
os.system("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys")
36+
if not os.path.exists(os.path.expanduser("~/.ssh/id_rsa")):
37+
os.system("ssh-keygen -P '' -m pem -f ~/.ssh/id_rsa")
38+
os.system("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys")
39+
3840
# also generate it for the sudo user
39-
os.system("sudo ssh-keygen -P '' -m pem -f /var/root/.ssh/id_rsa")
40-
os.system("sudo cat /var/root/.ssh/id_rsa.pub | sudo tee -a /var/root/.ssh/authorized_keys")
41+
if os.system("sudo [ -f /var/root/.ssh/id_rsa ]") != 0:
42+
os.system("sudo ssh-keygen -P '' -m pem -f /var/root/.ssh/id_rsa")
43+
os.system("sudo cat /var/root/.ssh/id_rsa.pub | sudo tee -a /var/root/.ssh/authorized_keys")
44+
4145
os.chmod(os.path.expanduser('~/.ssh'), int('0700', 8))
4246
os.chmod(os.path.expanduser('~/.ssh/authorized_keys'), int('0600', 8))
4347
# run chmod through sudo since it's owned by root
44-
os.system('sudo chmod 600 /var/root/.ssh')
48+
os.system('sudo chmod 700 /var/root/.ssh')
4549
os.system('sudo chmod 600 /var/root/.ssh/authorized_keys')
4650

4751
if os.path.expanduser('~mitogen__user1') == '~mitogen__user1':

ansible_mitogen/loaders.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import ansible
4646

4747
ANSIBLE_VERSION_MIN = (2, 10)
48-
ANSIBLE_VERSION_MAX = (2, 10)
48+
ANSIBLE_VERSION_MAX = (2, 11)
4949

5050
NEW_VERSION_MSG = (
5151
"Your Ansible version (%s) is too recent. The most recent version\n"
@@ -79,7 +79,7 @@ def assert_supported_release():
7979

8080
if v[:2] > ANSIBLE_VERSION_MAX:
8181
raise ansible.errors.AnsibleError(
82-
NEW_VERSION_MSG % (ansible.__version__, ANSIBLE_VERSION_MAX)
82+
NEW_VERSION_MSG % (v, ANSIBLE_VERSION_MAX)
8383
)
8484

8585

ansible_mitogen/transport_config.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def private_key_file(self):
451451
return self._play_context.private_key_file
452452

453453
def ssh_executable(self):
454-
return self._play_context.ssh_executable
454+
return C.config.get_config_value("ssh_executable", plugin_type="connection", plugin_name="ssh", variables=self._task_vars.get("vars", {}))
455455

456456
def timeout(self):
457457
return self._play_context.timeout
@@ -467,9 +467,9 @@ def ssh_args(self):
467467
return [
468468
mitogen.core.to_text(term)
469469
for s in (
470-
getattr(self._play_context, 'ssh_args', ''),
471-
getattr(self._play_context, 'ssh_common_args', ''),
472-
getattr(self._play_context, 'ssh_extra_args', '')
470+
C.config.get_config_value("ssh_args", plugin_type="connection", plugin_name="ssh", variables=self._task_vars.get("vars", {})),
471+
C.config.get_config_value("ssh_common_args", plugin_type="connection", plugin_name="ssh", variables=self._task_vars.get("vars", {})),
472+
C.config.get_config_value("ssh_extra_args", plugin_type="connection", plugin_name="ssh", variables=self._task_vars.get("vars", {}))
473473
)
474474
for term in ansible.utils.shlex.shlex_split(s or '')
475475
]
@@ -679,10 +679,7 @@ def private_key_file(self):
679679
)
680680

681681
def ssh_executable(self):
682-
return (
683-
self._host_vars.get('ansible_ssh_executable') or
684-
C.ANSIBLE_SSH_EXECUTABLE
685-
)
682+
return C.config.get_config_value("ssh_executable", plugin_type="connection", plugin_name="ssh", variables=self._task_vars.get("vars", {}))
686683

687684
def timeout(self):
688685
# TODO: must come from PlayContext too.
@@ -699,22 +696,9 @@ def ssh_args(self):
699696
return [
700697
mitogen.core.to_text(term)
701698
for s in (
702-
(
703-
self._host_vars.get('ansible_ssh_args') or
704-
getattr(C, 'ANSIBLE_SSH_ARGS', None) or
705-
os.environ.get('ANSIBLE_SSH_ARGS')
706-
# TODO: ini entry. older versions.
707-
),
708-
(
709-
self._host_vars.get('ansible_ssh_common_args') or
710-
os.environ.get('ANSIBLE_SSH_COMMON_ARGS')
711-
# TODO: ini entry.
712-
),
713-
(
714-
self._host_vars.get('ansible_ssh_extra_args') or
715-
os.environ.get('ANSIBLE_SSH_EXTRA_ARGS')
716-
# TODO: ini entry.
717-
),
699+
C.config.get_config_value("ssh_args", plugin_type="connection", plugin_name="ssh", variables=self._task_vars.get("vars", {})),
700+
C.config.get_config_value("ssh_common_args", plugin_type="connection", plugin_name="ssh", variables=self._task_vars.get("vars", {})),
701+
C.config.get_config_value("ssh_extra_args", plugin_type="connection", plugin_name="ssh", variables=self._task_vars.get("vars", {}))
718702
)
719703
for term in ansible.utils.shlex.shlex_split(s)
720704
if s

docs/ansible_detailed.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@ Testimonials
145145
Noteworthy Differences
146146
----------------------
147147

148-
* Ansible 2.3-2.9 are supported along with Python 2.6, 2.7, 3.6 and 3.7. Verify
149-
your installation is running one of these versions by checking ``ansible
150-
--version`` output.
148+
* Mitogen 0.2.x supports Ansible 2.3-2.9; with Python 2.6, 2.7, or 3.6.
149+
Mitogen 0.3.1+ supports Ansible 2.10, 3, and 4; with Python 2.7, or 3.6-3.9.
150+
Verify your installation is running one of these versions by checking
151+
``ansible --version`` output.
151152

152153
* The ``raw`` action executes as a regular Mitogen connection, which requires
153154
Python on the target, precluding its use for installing Python. This will be

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ To avail of fixes in an unreleased version, please download a ZIP file
2121
v0.3.1.dev0 (unreleased)
2222
------------------------
2323

24+
* :gh:issue:`834` Support for Ansible 3 and 4 (ansible-core 2.11)
2425
* :gh:issue:`869` Continuous Integration tests are now run with Tox
2526
* :gh:issue:`869` Continuous Integration tests now cover CentOS 6 & 8, Debian 9 & 11, Ubuntu 16.04 & 20.04
2627
* :gh:issue:`860` Add initial support for podman connection (w/o Ansible support yet)

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def long_description():
6464
zip_safe = False,
6565
classifiers = [
6666
'Environment :: Console',
67+
'Frameworks :: Ansible',
6768
'Intended Audience :: System Administrators',
6869
'License :: OSI Approved :: BSD License',
6970
'Operating System :: MacOS :: MacOS X',

0 commit comments

Comments
 (0)