Skip to content

Commit df98f9f

Browse files
committed
WIP
1 parent 3b2b03b commit df98f9f

File tree

11 files changed

+104
-106
lines changed

11 files changed

+104
-106
lines changed

.github/workflows/tests.yml

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -24,58 +24,12 @@ jobs:
2424
fail-fast: false
2525
matrix:
2626
include:
27-
- name: Ans_27_210
28-
tox_env: py27-mode_ansible-ansible2.10
2927
- name: Ans_27_4
3028
tox_env: py27-mode_ansible-ansible4
3129

32-
- name: Ans_36_210
33-
python_version: '3.6'
34-
tox_env: py36-mode_ansible-ansible2.10
3530
- name: Ans_36_4
3631
python_version: '3.6'
3732
tox_env: py36-mode_ansible-ansible4
38-
39-
- name: Ans_311_210
40-
python_version: '3.11'
41-
tox_env: py311-mode_ansible-ansible2.10
42-
- name: Ans_311_3
43-
python_version: '3.11'
44-
tox_env: py311-mode_ansible-ansible3
45-
- name: Ans_311_4
46-
python_version: '3.11'
47-
tox_env: py311-mode_ansible-ansible4
48-
- name: Ans_311_5
49-
python_version: '3.11'
50-
tox_env: py311-mode_ansible-ansible5
51-
- name: Ans_313_6
52-
python_version: '3.13'
53-
tox_env: py313-mode_ansible-ansible6
54-
- name: Ans_313_7
55-
python_version: '3.13'
56-
tox_env: py313-mode_ansible-ansible7
57-
- name: Ans_313_8
58-
python_version: '3.13'
59-
tox_env: py313-mode_ansible-ansible8
60-
- name: Ans_313_9
61-
python_version: '3.13'
62-
tox_env: py313-mode_ansible-ansible9
63-
- name: Ans_313_10
64-
python_version: '3.13'
65-
tox_env: py313-mode_ansible-ansible10
66-
- name: Van_313_10
67-
python_version: '3.13'
68-
tox_env: py313-mode_ansible-ansible10-strategy_linear
69-
70-
- name: Mito_27
71-
tox_env: py27-mode_mitogen
72-
- name: Mito_36
73-
python_version: '3.6'
74-
tox_env: py36-mode_mitogen
75-
- name: Mito_313
76-
python_version: '3.13'
77-
tox_env: py313-mode_mitogen
78-
7933
steps:
8034
- uses: actions/checkout@v4
8135
- uses: actions/setup-python@v5
@@ -164,24 +118,10 @@ jobs:
164118
fail-fast: false
165119
matrix:
166120
include:
167-
- name: Mito_27
168-
tox_env: py27-mode_mitogen
169121
- name: Mito_313
170122
python_version: '3.13'
171123
tox_env: py313-mode_mitogen
172124

173-
- name: Loc_27_210
174-
tox_env: py27-mode_localhost-ansible2.10
175-
- name: Loc_313_10
176-
python_version: '3.13'
177-
tox_env: py313-mode_localhost-ansible10
178-
179-
- name: Van_27_210
180-
tox_env: py27-mode_localhost-ansible2.10-strategy_linear
181-
- name: Van_313_10
182-
python_version: '3.13'
183-
tox_env: py313-mode_localhost-ansible10-strategy_linear
184-
185125
steps:
186126
- uses: actions/checkout@v4
187127
- uses: actions/setup-python@v5

ansible_mitogen/runner.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@
4949
import shutil
5050
import sys
5151
import tempfile
52+
import textwrap
5253
import traceback
5354
import types
5455

56+
from ansible.module_utils.common.text.converters import to_native
5557
from ansible.module_utils.six.moves import shlex_quote
5658

5759
import mitogen.core
@@ -75,6 +77,7 @@
7577
# Prevent accidental import of an Ansible module from hanging on stdin read.
7678
import ansible.module_utils.basic
7779
ansible.module_utils.basic._ANSIBLE_ARGS = '{}'
80+
import ansible.module_utils.common.respawn
7881

7982
# For tasks that modify /etc/resolv.conf, non-Debian derivative glibcs cache
8083
# resolv.conf at startup and never implicitly reload it. Cope with that via an
@@ -622,6 +625,20 @@ def revert(self):
622625
sys.argv[:] = self.original
623626

624627

628+
def _create_payload():
629+
smuggled_args = getattr(ansible.module_utils.basic, '_ANSIBLE_ARGS')
630+
if not smuggled_args:
631+
raise Exception('unable to access ansible.module_utils.basic._ANSIBLE_ARGS (not launched by AnsiballZ?)')
632+
633+
assert 0, '%r, %r, spec %r' % (
634+
sys.modules['__main__'],
635+
' '.join('%s=%r' % (s, getattr(sys.modules['__main__'], s)) for s in sorted(dir(sys.modules['__main__']))),
636+
' '.join('%s=%r' % (s, getattr(sys.modules['__main__'].__spec__, s)) for s in sorted(dir(sys.modules['__main__'].__spec__))),
637+
)
638+
module_fqn = sys.modules['__main__']._module_fqn
639+
modlib_path = sys.modules['__main__']._modlib_path
640+
641+
625642
class NewStyleStdio(object):
626643
"""
627644
Patch ansible.module_utils.basic argument globals.
@@ -640,11 +657,15 @@ def __init__(self, args, temp_dir):
640657
self.original_get_path = getattr(ansible.module_utils.basic,
641658
'get_module_path', None)
642659
ansible.module_utils.basic.get_module_path = self._get_path
660+
#self.original_create_payload = getattr(ansible.module_utils.common.respawn,
661+
# '_create_payload', None)
662+
#ansible.module_utils.common.respawn._create_payload = _create_payload
643663

644664
def _get_path(self):
645665
return self.temp_dir
646666

647667
def revert(self):
668+
#ansible.module_utils.common.respawn._create_payload = self.original_create_payload
648669
ansible.module_utils.basic.get_module_path = self.original_get_path
649670
sys.stdout = self.original_stdout
650671
sys.stderr = self.original_stderr
@@ -978,10 +999,7 @@ def _get_code(self):
978999
True, # dont_inherit
9791000
))
9801001

981-
if mitogen.core.PY3:
982-
main_module_name = '__main__'
983-
else:
984-
main_module_name = b'__main__'
1002+
main_module_name = '__main__'
9851003

9861004
def _handle_magic_exception(self, mod, exc):
9871005
"""
@@ -1032,6 +1050,9 @@ def _run(self):
10321050
'ansible_module_' + os.path.basename(self.path),
10331051
)
10341052

1053+
# CREDIT https://github.com/phemmer
1054+
# https://github.com/mitogen-hq/mitogen/issues/849#issuecomment-988207114
1055+
sys.modules['__main__']._module_fqn = self.py_module_name
10351056
code = self._get_code()
10361057
rc = 2
10371058
try:

ansible_mitogen/target.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@
6060
# ansible.module_utils.basic. Mitogen's importer will refuse such an import, so
6161
# we must setup a fake "__main__" before that module is ever imported. The
6262
# str() is to cast Unicode to bytes on Python 2.6.
63-
if not sys.modules.get(str('__main__')):
64-
sys.modules[str('__main__')] = types.ModuleType(str('__main__'))
63+
if '__main__' not in sys.modules:
64+
sys.modules['__main__'] = types.ModuleType(
65+
'__main__', doc='ansible_mitogen.target __main__ module substitute',
66+
)
6567

6668
import ansible.module_utils.json_utils
6769

tests/ansible/all.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
- import_playbook: setup/all.yml
22
tags: setup
3-
- import_playbook: regression/all.yml
4-
tags: regression
53
- import_playbook: integration/all.yml
64
tags: integration
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
---
22
pkg_mgr_python_interpreter: python
3+
pkg_repos_gpg_keys: []
34
pkg_repos_overrides: []
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pkg_repos_gpg_keys:
2+
- src: debian-archive-bullseye-automatic.gpg # Debian 11
3+
- src: debian-archive-bookworm-automatic.gpg # Debian 12

tests/ansible/integration/all.yml

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,4 @@
22
#
33
# This playbook imports all tests that are known to work at present.
44
#
5-
6-
- import_playbook: action/all.yml
7-
tags: action
8-
- import_playbook: async/all.yml
9-
tags: async
10-
- import_playbook: become/all.yml
11-
tags: become
12-
- import_playbook: connection/all.yml
13-
tags: connection
14-
- import_playbook: connection_delegation/all.yml
15-
tags: connection_delegation
16-
- import_playbook: connection_loader/all.yml
17-
tags: connection_loader
18-
- import_playbook: context_service/all.yml
19-
tags: context_service
20-
- import_playbook: glibc_caches/all.yml
21-
tags: glibc_caches
22-
- import_playbook: interpreter_discovery/all.yml
23-
tags: interpreter_discovery
24-
- import_playbook: local/all.yml
25-
tags: local
26-
- import_playbook: module_utils/all.yml
27-
tags: module_utils
28-
- import_playbook: playbook_semantics/all.yml
29-
tags: playbook_semantics
30-
- import_playbook: process/all.yml
31-
tags: process
32-
- import_playbook: runner/all.yml
33-
tags: runner
34-
- import_playbook: ssh/all.yml
35-
tags: ssh
36-
- import_playbook: strategy/all.yml
37-
tags: strategy
38-
- import_playbook: stub_connections/all.yml
39-
tags: stub_connections
40-
- import_playbook: transport_config/all.yml
41-
tags: transport_config
5+
- import_playbook: package_managers/all.yml
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
- name: integration/package_managers/all.yml
2+
hosts: test-targets
3+
gather_facts: true
4+
# Most OS package managers need root. Homebrew refuses to run as root. This
5+
# approximates "pkg_mgr == homebrew" for the Linux & macOS runners in CI.
6+
become: "{{ inventory_hostname in (groups.linux | default([])) }}"
7+
vars:
8+
ansible_python_interpreter: auto
9+
package: rsync # Chosen to exist in all tested distros/package managers
10+
tasks:
11+
- name: Switch to archived package repositories
12+
copy:
13+
dest: "{{ item.dest }}"
14+
content: "{{ item.content }}"
15+
mode: u=rw,go=r
16+
loop: "{{ pkg_repos_overrides }}"
17+
loop_control:
18+
label: "{{ item.dest }}"
19+
20+
- name: Add signing keys
21+
copy:
22+
src: "{{ item.src }}"
23+
dest: "/etc/apt/trusted.gpg.d/{{ item.src | basename }}"
24+
mode: u=rw,go=r
25+
loop: "{{ pkg_repos_gpg_keys }}"
26+
27+
- name: Update package index
28+
apt:
29+
update_cache: true
30+
when:
31+
- ansible_facts.pkg_mgr in ["apt"]
32+
33+
- name: Test package module 1st call
34+
package:
35+
name: "{{ package }}"
36+
state: present
37+
38+
- name: Test package module 2nd call
39+
package:
40+
name: "{{ package }}"
41+
state: present
42+
43+
- name: Test dnf module 1st call
44+
dnf:
45+
name: "{{ package }}"
46+
state: present
47+
when:
48+
- ansible_facts.pkg_mgr == 'dnf'
49+
50+
- name: Test dnf module 2nd call
51+
dnf:
52+
name: "{{ package }}"
53+
state: present
54+
when:
55+
- ansible_facts.pkg_mgr == 'dnf'
56+
57+
- name: Test apt module 1st call
58+
apt:
59+
name: "{{ package }}"
60+
state: present
61+
when:
62+
- ansible_facts.pkg_mgr == 'apt'
63+
64+
- name: Test apt module 2nd call
65+
apt:
66+
name: "{{ package }}"
67+
state: present
68+
when:
69+
- ansible_facts.pkg_mgr == 'apt'
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)