Prevent conditional templating errors from masking task output. Fixes #37187 (#74891)

This commit is contained in:
Matt Martz 2021-06-03 14:11:01 -05:00 committed by GitHub
parent 8f82e6327f
commit ac77911491
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 2 deletions

View file

@ -0,0 +1,4 @@
bugfixes:
- >-
``failed_when``/``changed_when`` - Catch templating errors to prevent masking of module output
(https://github.com/ansible/ansible/issues/37187)

View file

@ -671,8 +671,14 @@ class TaskExecutor:
# if we didn't skip this task, use the helpers to evaluate the changed/ # if we didn't skip this task, use the helpers to evaluate the changed/
# failed_when properties # failed_when properties
if 'skipped' not in result: if 'skipped' not in result:
_evaluate_changed_when_result(result) try:
_evaluate_failed_when_result(result) condname = 'changed'
_evaluate_changed_when_result(result)
condname = 'failed'
_evaluate_failed_when_result(result)
except AnsibleError as e:
result['failed'] = True
result['%s_when_result' % condname] = to_text(e)
if retries > 1: if retries > 1:
cond = Conditional(loader=self._loader) cond = Conditional(loader=self._loader)

View file

@ -59,3 +59,15 @@
assert: assert:
that: that:
- groupby is not changed - groupby is not changed
- name: invalid conditional
command: echo foo
changed_when: boomboomboom
register: invalid_conditional
ignore_errors: true
- assert:
that:
- invalid_conditional is failed
- invalid_conditional.stdout is defined
- invalid_conditional.changed_when_result is contains('boomboomboom')

View file

@ -66,3 +66,15 @@
that: that:
- "'failed' in result and not result.failed" - "'failed' in result and not result.failed"
- "'failed_when_result' in result and not result.failed_when_result" - "'failed_when_result' in result and not result.failed_when_result"
- name: invalid conditional
command: echo foo
failed_when: boomboomboom
register: invalid_conditional
ignore_errors: true
- assert:
that:
- invalid_conditional is failed
- invalid_conditional.stdout is defined
- invalid_conditional.failed_when_result is contains('boomboomboom')