This commit is contained in:
parent
8f82e6327f
commit
ac77911491
4 changed files with 36 additions and 2 deletions
4
changelogs/fragments/37187-catch-cond-tmpl-errors.yml
Normal file
4
changelogs/fragments/37187-catch-cond-tmpl-errors.yml
Normal 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)
|
|
@ -671,8 +671,14 @@ class TaskExecutor:
|
|||
# if we didn't skip this task, use the helpers to evaluate the changed/
|
||||
# failed_when properties
|
||||
if 'skipped' not in result:
|
||||
_evaluate_changed_when_result(result)
|
||||
_evaluate_failed_when_result(result)
|
||||
try:
|
||||
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:
|
||||
cond = Conditional(loader=self._loader)
|
||||
|
|
|
@ -59,3 +59,15 @@
|
|||
assert:
|
||||
that:
|
||||
- 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')
|
||||
|
|
|
@ -66,3 +66,15 @@
|
|||
that:
|
||||
- "'failed' in result and not result.failed"
|
||||
- "'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')
|
||||
|
|
Loading…
Reference in a new issue