diff --git a/changelogs/fragments/56458-yum-fix-false-error-msg-autoremove.yaml b/changelogs/fragments/56458-yum-fix-false-error-msg-autoremove.yaml new file mode 100644 index 0000000000..7d6f549b54 --- /dev/null +++ b/changelogs/fragments/56458-yum-fix-false-error-msg-autoremove.yaml @@ -0,0 +1,2 @@ +bugfixes: + - yum - Fix false error message about autoremove not being supported (https://github.com/ansible/ansible/issues/56458) diff --git a/lib/ansible/modules/packaging/os/yum.py b/lib/ansible/modules/packaging/os/yum.py index d517789586..107bd3f65d 100644 --- a/lib/ansible/modules/packaging/os/yum.py +++ b/lib/ansible/modules/packaging/os/yum.py @@ -1083,9 +1083,8 @@ class YumModule(YumDnf): res['msg'] = err if rc != 0: - if self.autoremove: - if 'No such command' not in out: - self.module.fail_json(msg='Version of YUM too old for autoremove: Requires yum 3.4.3 (RHEL/CentOS 7+)') + if self.autoremove and 'No such command' in out: + self.module.fail_json(msg='Version of YUM too old for autoremove: Requires yum 3.4.3 (RHEL/CentOS 7+)') else: self.module.fail_json(**res)