mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
task_result _check_key should handle empty results (#16766)
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
This commit is contained in:
parent
4f7996fbc1
commit
eb2a3a91a8
2 changed files with 13 additions and 1 deletions
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue