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 14d766d90c5..d0dfda7b4c5 100644 --- a/lib/ansible/modules/packaging/os/dnf.py +++ b/lib/ansible/modules/packaging/os/dnf.py @@ -588,6 +588,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( @@ -601,15 +610,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: - try: - base.update_cache() - except dnf.exceptions.RepoError as e: - self.module.fail_json( - msg="{0}".format(to_text(e)), - results=[], - rc=1 - ) return base diff --git a/test/integration/targets/dnf/tasks/dnf.yml b/test/integration/targets/dnf/tasks/dnf.yml index 7b9306af277..23bde538dc5 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