ansible_mitogen: Fix dnf module by patching include of dnf.cli (#1230)

* fix dnf module import

* add changelog
pull/1235/head
Sergey Putko 10 months ago committed by GitHub
parent 45472c6edc
commit 186404829d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -615,6 +615,23 @@ def _fix_py35(invocation, module_source):
invocation._overridden_sources[invocation.module_path] = module_source
def _fix_dnf(invocation, module_source):
"""
Handles edge case where dnf ansible module showed failure due to a missing import in the dnf module.
Specifically addresses errors like "Failed loading plugin 'debuginfo-install': module 'dnf' has no attribute 'cli'".
https://github.com/mitogen-hq/mitogen/issues/1143
This issue is resolved by adding 'dnf.cli' to the import statement in the module source.
This works in vanilla Ansible but not in Mitogen otherwise.
"""
if invocation.module_name in {'ansible.builtin.dnf', 'ansible.legacy.dnf', 'dnf'} and \
invocation.module_path not in invocation._overridden_sources:
module_source = module_source.replace(
b"import dnf\n",
b"import dnf, dnf.cli\n"
)
invocation._overridden_sources[invocation.module_path] = module_source
def _load_collections(invocation):
"""
Special loader that ensures that `ansible_collections` exist as a module path for import
@ -652,6 +669,7 @@ def invoke(invocation):
module_source = invocation.get_module_source()
_fix_py35(invocation, module_source)
_fix_dnf(invocation, module_source)
_planner_by_path[invocation.module_path] = _get_planner(
invocation,
module_source

@ -35,6 +35,7 @@ In progress (unreleased)
* :gh:issue:`1213` :mod:`ansible_mitogen`: Return ``stderr_lines`` from
``_low_level_execute_command()``
* :gh:issue:`1227` tests: Name transport_config tests that use ``mitogen_via``
* :gh:issue:`1143` :mod:`ansible_mitogen`: Fix dnf module include for dnf.cli
v0.3.21 (2025-01-20)

Loading…
Cancel
Save