mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
dnf: fix wildcard matching for state: absent (#56013)
* dnf: fix wildcard matching for state: absent Fixes #55938 * Add changelog... * Fix sanity check failure...
This commit is contained in:
parent
e98e98757d
commit
826b99d4bd
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)"
|
|
@ -1108,6 +1108,14 @@ class DnfModule(YumDnf):
|
||||||
|
|
||||||
installed = self.base.sack.query().installed()
|
installed = self.base.sack.query().installed()
|
||||||
for pkg_spec in pkg_specs:
|
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()))
|
installed_pkg = list(map(str, installed.filter(name=pkg_spec).run()))
|
||||||
if installed_pkg:
|
if installed_pkg:
|
||||||
candidate_pkg = self._packagename_dict(installed_pkg[0])
|
candidate_pkg = self._packagename_dict(installed_pkg[0])
|
||||||
|
|
|
@ -256,6 +256,26 @@
|
||||||
that:
|
that:
|
||||||
- rpm_main_result.rc == 0
|
- rpm_main_result.rc == 0
|
||||||
- rpm_weak_result.rc == 1 # the weak dependency shouldn't be installed
|
- 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:
|
always:
|
||||||
- name: Clean up
|
- name: Clean up
|
||||||
dnf:
|
dnf:
|
||||||
|
|
Loading…
Reference in a new issue