diff --git a/lib/ansible/executor/task_result.py b/lib/ansible/executor/task_result.py index 457a094b734..f7ba7d092c4 100644 --- a/lib/ansible/executor/task_result.py +++ b/lib/ansible/executor/task_result.py @@ -62,7 +62,7 @@ class TaskResult: return self._check_key('unreachable') def _check_key(self, key): - if 'results' in self._result and self._task.loop: + if self._result.get('results', []) and self._task.loop: flag = False for res in self._result.get('results', []): if isinstance(res, dict): diff --git a/test/integration/roles/test_yum/tasks/yum.yml b/test/integration/roles/test_yum/tasks/yum.yml index f6acbfef775..f285326f5f6 100644 --- a/test/integration/roles/test_yum/tasks/yum.yml +++ b/test/integration/roles/test_yum/tasks/yum.yml @@ -185,3 +185,15 @@ - name: uninstall sos and sharutils yum: name=sos,sharutils state=removed + +- name: install non-existent rpm + yum: name="{{ item }}" + with_items: + - does-not-exist + register: non_existent_rpm + ignore_errors: True + +- name: check non-existent rpm install failed + assert: + that: + - non_existent_rpm|failed