From 21d692cace414bdab78dc13f88f6ca013a7fec32 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Fri, 5 Apr 2019 16:28:24 -0500 Subject: [PATCH] fix dnf module removal in dnf upstream 4.2.2+ (#54923) * fix dnf module removal in dnf upstream 4.2.2+ Signed-off-by: Adam Miller * Remove extra blank line in changelog fragment. --- changelogs/fragments/dnf-4.2.2-module-remove.yaml | 3 +++ lib/ansible/modules/packaging/os/dnf.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/dnf-4.2.2-module-remove.yaml diff --git a/changelogs/fragments/dnf-4.2.2-module-remove.yaml b/changelogs/fragments/dnf-4.2.2-module-remove.yaml new file mode 100644 index 00000000000..82dc1d62ae7 --- /dev/null +++ b/changelogs/fragments/dnf-4.2.2-module-remove.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - dnf - fix issue with dnf API calls to adapt to changes in upstream dnf version 4.2.2 diff --git a/lib/ansible/modules/packaging/os/dnf.py b/lib/ansible/modules/packaging/os/dnf.py index 9e791218178..7a395675a63 100644 --- a/lib/ansible/modules/packaging/os/dnf.py +++ b/lib/ansible/modules/packaging/os/dnf.py @@ -600,13 +600,17 @@ class DnfModule(YumDnf): """Return a fully configured dnf Base object.""" base = dnf.Base() self._configure_base(base, conf_file, disable_gpg_check, installroot) - self._specify_repositories(base, disablerepo, enablerepo) try: base.init_plugins(set(self.disable_plugin), set(self.enable_plugin)) base.pre_configure_plugins() + except AttributeError: + pass # older versions of dnf didn't require this and don't have these methods + self._specify_repositories(base, disablerepo, enablerepo) + try: base.configure_plugins() except AttributeError: pass # older versions of dnf didn't require this and don't have these methods + try: if self.update_cache: try: @@ -928,6 +932,7 @@ class DnfModule(YumDnf): if not self._is_module_installed(module): response['results'].append("Module {0} installed.".format(module)) self.module_base.install([module]) + self.module_base.enable([module]) except dnf.exceptions.MarkingErrors as e: failure_response['failures'].append( " ".join( @@ -1066,8 +1071,9 @@ class DnfModule(YumDnf): try: if self._is_module_installed(module): response['results'].append("Module {0} removed.".format(module)) - self.module_base.disable([module]) self.module_base.remove([module]) + self.module_base.disable([module]) + self.module_base.reset([module]) except dnf.exceptions.MarkingErrors as e: failure_response['failures'].append( " ".join(