From 479cbfc63c8261577b359b7703d7e6168c1a74f5 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Thu, 29 Oct 2015 19:23:42 -0400 Subject: [PATCH] Don't immediately fail on PlayContext setup As we may end up skipping the task due to conditionals. Fixes #12774 --- lib/ansible/executor/task_executor.py | 33 ++++++++++++++++++--------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 2fdc1e9b56b..8176373fc42 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -259,17 +259,24 @@ class TaskExecutor: templar = Templar(loader=self._loader, shared_loader_obj=self._shared_loader_obj, variables=variables) - # apply the given task's information to the connection info, - # which may override some fields already set by the play or - # the options specified on the command line - self._play_context = self._play_context.set_task_and_variable_override(task=self._task, variables=variables, templar=templar) - - # fields set from the play/task may be based on variables, so we have to - # do the same kind of post validation step on it here before we use it. - # We also add "magic" variables back into the variables dict to make sure - # a certain subset of variables exist. - self._play_context.update_vars(variables) - self._play_context.post_validate(templar=templar) + context_validation_error = None + try: + # apply the given task's information to the connection info, + # which may override some fields already set by the play or + # the options specified on the command line + self._play_context = self._play_context.set_task_and_variable_override(task=self._task, variables=variables, templar=templar) + + # fields set from the play/task may be based on variables, so we have to + # do the same kind of post validation step on it here before we use it. + self._play_context.post_validate(templar=templar) + + # We also add "magic" variables back into the variables dict to make sure + # a certain subset of variables exist. + self._play_context.update_vars(variables) + except AnsibleError as e: + # save the error, which we'll raise later if we don't end up + # skipping this task during the conditional evaluation step + context_validation_error = e # Evaluate the conditional (if any) for this task, which we do before running # the final task post-validation. We do this before the post validation due to @@ -284,6 +291,10 @@ class TaskExecutor: if self._task.action != 'include': raise + # if we ran into an error while setting up the PlayContext, raise it now + if context_validation_error is not None: + raise context_validation_error + # if this task is a TaskInclude, we just return now with a success code so the # main thread can expand the task list for the given host if self._task.action == 'include':