diff --git a/changelogs/fragments/dnf-update-cache-broken-transaction.yaml b/changelogs/fragments/dnf-update-cache-broken-transaction.yaml new file mode 100644 index 00000000000..b6501259295 --- /dev/null +++ b/changelogs/fragments/dnf-update-cache-broken-transaction.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - "dnf - fix update_cache combined with install operation to not cause dnf transaction failure" diff --git a/lib/ansible/modules/packaging/os/dnf.py b/lib/ansible/modules/packaging/os/dnf.py index 45abb40c0b3..e388834e9bc 100644 --- a/lib/ansible/modules/packaging/os/dnf.py +++ b/lib/ansible/modules/packaging/os/dnf.py @@ -579,6 +579,15 @@ class DnfModule(YumDnf): except AttributeError: pass # older versions of dnf didn't require this and don't have these methods try: + if self.update_cache: + try: + base.update_cache() + except dnf.exceptions.RepoError as e: + self.module.fail_json( + msg="{0}".format(to_text(e)), + results=[], + rc=1 + ) base.fill_sack(load_system_repo='auto') except dnf.exceptions.RepoError as e: self.module.fail_json( @@ -592,8 +601,6 @@ class DnfModule(YumDnf): if self.security: key = {'advisory_type__eq': 'security'} base._update_security_filters = [base.sack.query().filter(**key)] - if self.update_cache: - base.update_cache() return base def list_items(self, command): diff --git a/test/integration/targets/dnf/tasks/dnf.yml b/test/integration/targets/dnf/tasks/dnf.yml index 5ed4fb1a302..990e0f1106c 100644 --- a/test/integration/targets/dnf/tasks/dnf.yml +++ b/test/integration/targets/dnf/tasks/dnf.yml @@ -50,6 +50,7 @@ dnf: name: sos state: present + update_cache: True register: dnf_result - name: check sos with rpm