diff --git a/lib/ansible/modules/packaging/os/dnf.py b/lib/ansible/modules/packaging/os/dnf.py index d8c2e14787..08602e53ee 100644 --- a/lib/ansible/modules/packaging/os/dnf.py +++ b/lib/ansible/modules/packaging/os/dnf.py @@ -1087,10 +1087,10 @@ class DnfModule(YumDnf): self.module.exit_json(**response) else: response['changed'] = True + if failure_response['failures']: + failure_response['msg'] = 'Failed to install some of the specified packages', + self.module.fail_json(**failure_response) if self.module.check_mode: - if failure_response['failures']: - failure_response['msg'] = 'Failed to install some of the specified packages', - self.module.fail_json(**failure_response) response['msg'] = "Check mode: No changes made, but would have if not in check mode" self.module.exit_json(**response)