mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
respawn copr module when dnf is missing (#6522)
* respawn copr module when dnf is missing Fixes: https://bugzilla.redhat.com/2203513 * don't guard common.respawn module_util import
This commit is contained in:
parent
e588e675d9
commit
bd6cec2105
3 changed files with 20 additions and 6 deletions
4
changelogs/fragments/6522-copr-respawn.yaml
Normal file
4
changelogs/fragments/6522-copr-respawn.yaml
Normal file
|
@ -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)."
|
|
@ -97,6 +97,7 @@ except ImportError:
|
||||||
DNF_IMP_ERR = traceback.format_exc()
|
DNF_IMP_ERR = traceback.format_exc()
|
||||||
HAS_DNF_PACKAGES = False
|
HAS_DNF_PACKAGES = False
|
||||||
|
|
||||||
|
from ansible.module_utils.common import respawn
|
||||||
from ansible.module_utils.six.moves.urllib.error import HTTPError
|
from ansible.module_utils.six.moves.urllib.error import HTTPError
|
||||||
from ansible.module_utils.basic import missing_required_lib
|
from ansible.module_utils.basic import missing_required_lib
|
||||||
from ansible.module_utils import distro # pylint: disable=import-error
|
from ansible.module_utils import distro # pylint: disable=import-error
|
||||||
|
@ -104,6 +105,20 @@ from ansible.module_utils.basic import AnsibleModule # pylint: disable=import-e
|
||||||
from ansible.module_utils.urls import open_url # pylint: disable=import-error
|
from ansible.module_utils.urls import open_url # pylint: disable=import-error
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
class CoprModule(object):
|
||||||
"""The class represents a copr module.
|
"""The class represents a copr module.
|
||||||
|
|
||||||
|
@ -460,6 +475,7 @@ def run_module():
|
||||||
params = module.params
|
params = module.params
|
||||||
|
|
||||||
if not HAS_DNF_PACKAGES:
|
if not HAS_DNF_PACKAGES:
|
||||||
|
_respawn_dnf()
|
||||||
module.fail_json(msg=missing_required_lib("dnf"), exception=DNF_IMP_ERR)
|
module.fail_json(msg=missing_required_lib("dnf"), exception=DNF_IMP_ERR)
|
||||||
|
|
||||||
CoprModule.ansible_module = module
|
CoprModule.ansible_module = module
|
||||||
|
|
|
@ -10,12 +10,6 @@
|
||||||
ansible_distribution == 'Fedora'
|
ansible_distribution == 'Fedora'
|
||||||
or (ansible_os_family == 'RedHat' and ansible_distribution != 'Fedora'
|
or (ansible_os_family == 'RedHat' and ansible_distribution != 'Fedora'
|
||||||
and ansible_distribution_major_version | int >= 8)
|
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:
|
block:
|
||||||
- debug: var=copr_chroot
|
- debug: var=copr_chroot
|
||||||
- name: enable copr project
|
- name: enable copr project
|
||||||
|
|
Loading…
Reference in a new issue