summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Cammarata <jimi@sngx.net>2016-11-15 10:02:07 -0600
committerJames Cammarata <jimi@sngx.net>2016-11-15 10:40:50 -0600
commitc3fbe526ca52831aefdf367127adb1f18d8e9285 (patch)
treea0f9c5f9b8df3ad159da92d5e5d97303b0af2a31
parenteea3051a12cbec37f5125045b0676fea7a30826c (diff)
downloadansible-c3fbe526ca52831aefdf367127adb1f18d8e9285.tar.gz
Catch loop eval errors and only raise them again if the task is not skipped
This should help on issues like #16222. (cherry picked from commit 57cf5e431c69e7f8bb8607ff37fd51418249d03c)
-rw-r--r--lib/ansible/executor/task_executor.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py
index 7cdf402a90..959876527e 100644
--- a/lib/ansible/executor/task_executor.py
+++ b/lib/ansible/executor/task_executor.py
@@ -71,6 +71,7 @@ class TaskExecutor:
self._shared_loader_obj = shared_loader_obj
self._connection = None
self._rslt_q = rslt_q
+ self._loop_eval_error = None
def run(self):
'''
@@ -90,7 +91,13 @@ class TaskExecutor:
roledir = self._task._role._role_path
self._job_vars['roledir'] = roledir
- items = self._get_loop_items()
+ try:
+ items = self._get_loop_items()
+ except AnsibleUndefinedVariable as e:
+ # save the error raised here for use later
+ items = None
+ self._loop_eval_error = e
+
if items is not None:
if len(items) > 0:
item_results = self._run_loop(items)
@@ -377,6 +384,11 @@ class TaskExecutor:
if not self._task.evaluate_conditional(templar, variables):
display.debug("when evaluation failed, skipping this task")
return dict(changed=False, skipped=True, skip_reason='Conditional check failed', _ansible_no_log=self._play_context.no_log)
+ # since we're not skipping, if there was a loop evaluation error
+ # raised earlier we need to raise it now to halt the execution of
+ # this task
+ if self._loop_eval_error is not None:
+ raise self._loop_eval_error
except AnsibleError:
# skip conditional exception in the case of includes as the vars needed might not be avaiable except in the included tasks or due to tags
if self._task.action != 'include':