Don't immediately fail on PlayContext setup
As we may end up skipping the task due to conditionals. Fixes #12774
This commit is contained in:
parent
b73941b95f
commit
479cbfc63c
1 changed files with 21 additions and 10 deletions
|
@ -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)
|
||||
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.
|
||||
# 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)
|
||||
# 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':
|
||||
|
|
Loading…
Reference in a new issue