From 9155af20e31ff0f440084255957b728c876da359 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Sun, 5 Jul 2015 01:06:54 -0400 Subject: [PATCH] Make sure vars in debug tasks aren't templated too early If the syntax var={{something}} is used, that can be templated too early in the post_validation, leading the debug module to fail when it tries to template the same value in turn. --- lib/ansible/executor/task_executor.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 6d23548de3..ae840a4de6 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -231,9 +231,18 @@ class TaskExecutor: debug("when evaulation failed, skipping this task") return dict(changed=False, skipped=True, skip_reason='Conditional check failed') - # Now we do final validation on the task, which sets all fields to their final values + # Now we do final validation on the task, which sets all fields to their final values. + # In the case of debug tasks, we save any 'var' params and restore them after validating + # so that variables are not replaced too early. + prev_var = None + if self._task.action == 'debug' and 'var' in self._task.args: + prev_var = self._task.args.pop('var') + self._task.post_validate(templar=templar) + if prev_var is not None: + self._task.args['var'] = prev_var + # 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':