diff --git a/changelogs/fragments/dnf-group-removal.yaml b/changelogs/fragments/dnf-group-removal.yaml index df5373cf0c..44a90f0a38 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 f5144b55c9..61b21bd7ae 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