Skip to content

Commit

Permalink
dnf: fix wildcard matching for state: absent (#56013)
Browse files Browse the repository at this point in the history
* dnf: fix wildcard matching for state: absent

Fixes #55938

* Add changelog...

* Fix sanity check failure...

(cherry picked from commit 826b99d)
  • Loading branch information
mkrizek authored and abadger committed May 21, 2019
1 parent 235aa2b commit 411371a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
@@ -0,0 +1,2 @@
bugfixes:
- "dnf - fix wildcard matching for state: absent (https://github.com/ansible/ansible/issues/55938)"
8 changes: 8 additions & 0 deletions lib/ansible/modules/packaging/os/dnf.py
Expand Up @@ -1108,6 +1108,14 @@ def ensure(self):

installed = self.base.sack.query().installed()
for pkg_spec in pkg_specs:
# short-circuit installed check for wildcard matching
if '*' in pkg_spec:
try:
self.base.remove(pkg_spec)
except dnf.exceptions.MarkingError as e:
failure_response['failures'].append('{0} - {1}'.format(pkg_spec, to_native(e)))
continue

installed_pkg = list(map(str, installed.filter(name=pkg_spec).run()))
if installed_pkg:
candidate_pkg = self._packagename_dict(installed_pkg[0])
Expand Down
20 changes: 20 additions & 0 deletions test/integration/targets/dnf/tasks/repo.yml
Expand Up @@ -256,6 +256,26 @@
that:
- rpm_main_result.rc == 0
- rpm_weak_result.rc == 1 # the weak dependency shouldn't be installed

# https://github.com/ansible/ansible/issues/55938
- name: Install foo-*
dnf:
name: foo-*
state: present

- name: Uninstall foo-*
dnf:
name: foo-*
state: absent

- name: Check if all foo packages are removed
shell: rpm -qa foo-* | wc -l
register: rpm_result

- name: Verify rpm result
assert:
that:
- rpm_result.stdout == '0'
always:
- name: Clean up
dnf:
Expand Down

0 comments on commit 411371a

Please sign in to comment.