From 2fe150a1ef4abd3308b94a084f3d9cf516a420cc Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Thu, 20 Sep 2018 11:13:17 -0500 Subject: [PATCH] fix dnf wildcard pkg removal - fixes #27744 and #36970 (#45357) Signed-off-by: Adam Miller --- changelogs/fragments/dnf-group-removal.yaml | 1 + lib/ansible/modules/packaging/os/dnf.py | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/changelogs/fragments/dnf-group-removal.yaml b/changelogs/fragments/dnf-group-removal.yaml index df5373cf0c3..44a90f0a386 100644 --- a/changelogs/fragments/dnf-group-removal.yaml +++ b/changelogs/fragments/dnf-group-removal.yaml @@ -1,3 +1,4 @@ --- minor_changes: - "dnf - group removal does not work if group was installed with Ansible because of dnf upstream bug https://bugzilla.redhat.com/show_bug.cgi?id=1620324" + - "dnf removal with wildcards now works: Fixes https://github.com/ansible/ansible/issues/27744" diff --git a/lib/ansible/modules/packaging/os/dnf.py b/lib/ansible/modules/packaging/os/dnf.py index f5144b55c94..61b21bd7ae7 100644 --- a/lib/ansible/modules/packaging/os/dnf.py +++ b/lib/ansible/modules/packaging/os/dnf.py @@ -548,13 +548,15 @@ class DnfModule(YumDnf): # Disable repositories for repo_pattern in disablerepo: - for repo in repos.get_matching(repo_pattern): - repo.disable() + if repo_pattern: + for repo in repos.get_matching(repo_pattern): + repo.disable() # Enable repositories for repo_pattern in enablerepo: - for repo in repos.get_matching(repo_pattern): - repo.enable() + if repo_pattern: + for repo in repos.get_matching(repo_pattern): + repo.enable() def _base(self, conf_file, disable_gpg_check, disablerepo, enablerepo, installroot): """Return a fully configured dnf Base object.""" @@ -944,7 +946,7 @@ class DnfModule(YumDnf): installed = self.base.sack.query().installed() for pkg_spec in pkg_specs: - if installed.filter(name=pkg_spec): + if ("*" in pkg_spec) or installed.filter(name=pkg_spec): self.base.remove(pkg_spec) # Like the dnf CLI we want to allow recursive removal of dependent