Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

respawn copr module when dnf is missing #6522

Merged
merged 2 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelogs/fragments/6522-copr-respawn.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
minor_changes:
- "copr - respawn module to use the system python interpreter when the ``dnf`` python module is not available in ``ansible_python_interpreter``
(https://github.com/ansible-collections/community.general/pull/6522)."
25 changes: 25 additions & 0 deletions plugins/modules/copr.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,29 @@
from ansible.module_utils.basic import AnsibleModule # pylint: disable=import-error
from ansible.module_utils.urls import open_url # pylint: disable=import-error

HAS_RESPAWN_UTIL = False
if not HAS_DNF_PACKAGES:
try:
from ansible.module_utils.common import respawn
except ImportError:
pass
else:
HAS_RESPAWN_UTIL = True


def _respawn_dnf():
if respawn.has_respawned():
return
system_interpreters = (
"/usr/libexec/platform-python",
"/usr/bin/python3",
"/usr/bin/python2",
"/usr/bin/python",
)
interpreter = respawn.probe_interpreters_for_module(system_interpreters, "dnf")
if interpreter:
respawn.respawn_module(interpreter)


class CoprModule(object):
"""The class represents a copr module.
Expand Down Expand Up @@ -460,6 +483,8 @@ def run_module():
params = module.params

if not HAS_DNF_PACKAGES:
if HAS_RESPAWN_UTIL:
_respawn_dnf()
module.fail_json(msg=missing_required_lib("dnf"), exception=DNF_IMP_ERR)

CoprModule.ansible_module = module
Expand Down
6 changes: 0 additions & 6 deletions tests/integration/targets/copr/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
ansible_distribution == 'Fedora'
or (ansible_os_family == 'RedHat' and ansible_distribution != 'Fedora'
and ansible_distribution_major_version | int >= 8)
# The copr module imports dnf which is only available for the system Python
# interpreter.
- >
not (ansible_distribution == 'CentOS' and
ansible_distribution_major_version | int == 8 and not
ansible_python_version.startswith('3.6'))
block:
- debug: var=copr_chroot
- name: enable copr project
Expand Down