When a task result has an empty results list, the
list should be ignored when determining the results
of `_check_key`. Here the empty list is treated the
same as a non-existent list.
This fixes a bug that manifests itself with squashed
items - namely the task result contains the correct
value for the key, but an empty results list. The
empty results list was treated as zero failures
when deciding which handler to call - so the task
show as a success in the output, but is deemed to
have failed when deciding whether to continue.
This also demonstrates a mismatch between task
result processing and play iteration.
A test is also added for this case, but it would not
have caught the bug - because the bug is really in
the display, and not the success/failure of the
task (visually the test is more accurate).
Fixes ansible/ansible-modules-core#4214
(cherry picked from commit eb2a3a91a8e2baa59e8d2c7c97085e3be7a11f5a)
... | ... |
@@ -62,7 +62,7 @@ class TaskResult: |
62 | 62 |
return self._check_key('unreachable') |
63 | 63 |
|
64 | 64 |
def _check_key(self, key): |
65 |
- if 'results' in self._result and self._task.loop: |
|
65 |
+ if self._result.get('results', []) and self._task.loop: |
|
66 | 66 |
flag = False |
67 | 67 |
for res in self._result.get('results', []): |
68 | 68 |
if isinstance(res, dict): |
... | ... |
@@ -185,3 +185,15 @@ |
185 | 185 |
|
186 | 186 |
- name: uninstall sos and sharutils |
187 | 187 |
yum: name=sos,sharutils state=removed |
188 |
+ |
|
189 |
+- name: install non-existent rpm |
|
190 |
+ yum: name="{{ item }}" |
|
191 |
+ with_items: |
|
192 |
+ - does-not-exist |
|
193 |
+ register: non_existent_rpm |
|
194 |
+ ignore_errors: True |
|
195 |
+ |
|
196 |
+- name: check non-existent rpm install failed |
|
197 |
+ assert: |
|
198 |
+ that: |
|
199 |
+ - non_existent_rpm|failed |