From 2f5161628a3d6a6e021755bb6001c6873f518833 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Thu, 26 Apr 2018 13:39:44 -0500 Subject: [PATCH] Don't skip conditional exception on includes (#39377) * task_executor.py: Raise 'conditional exception' in case of 'include_*' Fixes #33632 Signed-off-by: Patrick Ringl * Re-organize tests, add static include test with undefined var * Remove unnecessary conditional --- lib/ansible/executor/task_executor.py | 4 +-- .../targets/include_import/runme.sh | 4 +++ .../undefined_var/include_tasks.yml | 5 +++ .../include_that_defines_var.yml | 5 +++ .../include_import/undefined_var/playbook.yml | 36 +++++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 test/integration/targets/include_import/undefined_var/include_tasks.yml create mode 100644 test/integration/targets/include_import/undefined_var/include_that_defines_var.yml create mode 100644 test/integration/targets/include_import/undefined_var/playbook.yml diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 13b7d24bc96..4924461f94d 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -471,9 +471,7 @@ class TaskExecutor: # loop error takes precedence if self._loop_eval_error is not None: raise self._loop_eval_error # pylint: disable=raising-bad-type - # skip conditional exception in the case of includes as the vars needed might not be available except in the included tasks or due to tags - if self._task.action not in ['include', 'include_tasks', 'include_role']: - raise + raise # Not skipping, if we had loop error raised earlier we need to raise it now to halt the execution of this task if self._loop_eval_error is not None: diff --git a/test/integration/targets/include_import/runme.sh b/test/integration/targets/include_import/runme.sh index 8c989518586..ef20bebc6d6 100755 --- a/test/integration/targets/include_import/runme.sh +++ b/test/integration/targets/include_import/runme.sh @@ -59,3 +59,7 @@ rm -f tasks/hello/*.yml # Inlcuded tasks should inherit attrs from non-dynamic blocks in parent chain # https://github.com/ansible/ansible/pull/38827 ANSIBLE_STRATEGY='linear' ansible-playbook test_grandparent_inheritance.yml -i ../../inventory "$@" + +# undefined_var +ANSIBLE_STRATEGY='linear' ansible-playbook undefined_var/playbook.yml -i ../../inventory "$@" +ANSIBLE_STRATEGY='free' ansible-playbook undefined_var/playbook.yml -i ../../inventory "$@" diff --git a/test/integration/targets/include_import/undefined_var/include_tasks.yml b/test/integration/targets/include_import/undefined_var/include_tasks.yml new file mode 100644 index 00000000000..56f06c97e2f --- /dev/null +++ b/test/integration/targets/include_import/undefined_var/include_tasks.yml @@ -0,0 +1,5 @@ +--- + +- debug: + msg: "This message comes from an 'include_tasks'-task! :-)" + register: "_include_tasks_task_result" diff --git a/test/integration/targets/include_import/undefined_var/include_that_defines_var.yml b/test/integration/targets/include_import/undefined_var/include_that_defines_var.yml new file mode 100644 index 00000000000..7f24a435f0e --- /dev/null +++ b/test/integration/targets/include_import/undefined_var/include_that_defines_var.yml @@ -0,0 +1,5 @@ +- vars: + _undefined: 'yes' + block: + - set_fact: + _include_defined_result: 'good' diff --git a/test/integration/targets/include_import/undefined_var/playbook.yml b/test/integration/targets/include_import/undefined_var/playbook.yml new file mode 100644 index 00000000000..0584fa8a681 --- /dev/null +++ b/test/integration/targets/include_import/undefined_var/playbook.yml @@ -0,0 +1,36 @@ +--- +- hosts: testhost + gather_facts: false + tasks: + - include_tasks: "include_tasks.yml" + ignore_errors: True + register: "_include_tasks_result" + when: + - "_undefined == 'yes'" + + - assert: + that: + - "_include_tasks_result is failed" + - "_include_tasks_task_result is not defined" + msg: "'include_tasks' did not evaluate it's attached condition and failed" + + - include_role: + name: "no_log" + ignore_errors: True + register: "_include_role_result" + when: + - "_undefined == 'yes'" + + - assert: + that: + - "_include_role_result is failed" + msg: "'include_role' did not evaluate it's attached condition and failed" + + - include: include_that_defines_var.yml + static: yes + when: + - "_undefined == 'yes'" + + - assert: + that: + - _include_defined_result == 'good'