Fixes #4549 Do not call lookup plugins when templating a task's name

This commit is contained in:
James Tanner 2013-10-25 10:27:38 -04:00
parent baccced4d4
commit 9b1fe455c6
2 changed files with 8 additions and 6 deletions

View file

@ -353,7 +353,7 @@ class PlayBook(object):
else:
name = task.name
self.callbacks.on_task_start(template(play.basedir, name, task.module_vars, lookup_fatal=False, filter_fatal=False), is_handler)
self.callbacks.on_task_start(template(play.basedir, name, task.module_vars, lookup_fatal=False, filter_fatal=False, lookups=False), is_handler)
if hasattr(self.callbacks, 'skip_task') and self.callbacks.skip_task:
ansible.callbacks.set_task(self.callbacks, None)
ansible.callbacks.set_task(self.runner_callbacks, None)

View file

@ -311,7 +311,7 @@ def legacy_varReplace(basedir, raw, vars, lookup_fatal=True, depth=0, expand_lis
return result
def template(basedir, input_value, vars, lookup_fatal=True, depth=-1, expand_lists=True, convert_bare=False, fail_on_undefined=False, filter_fatal=True):
def template(basedir, input_value, vars, lookup_fatal=True, depth=-1, expand_lists=True, convert_bare=False, fail_on_undefined=False, filter_fatal=True, lookups=True):
last_time = input_value
result = None
changed = True
@ -326,6 +326,7 @@ def template(basedir, input_value, vars, lookup_fatal=True, depth=-1, expand_lis
convert_bare=convert_bare,
fail_on_undefined=fail_on_undefined,
filter_fatal=filter_fatal,
lookups=lookups,
)
if last_time == result:
changed = False
@ -335,7 +336,7 @@ def template(basedir, input_value, vars, lookup_fatal=True, depth=-1, expand_lis
raise errors.AnsibleError("template recursion depth exceeded")
return result
def _template(basedir, varname, vars, lookup_fatal=True, depth=0, expand_lists=True, convert_bare=False, fail_on_undefined=False, filter_fatal=True):
def _template(basedir, varname, vars, lookup_fatal=True, depth=0, expand_lists=True, convert_bare=False, fail_on_undefined=False, filter_fatal=True, lookups=True):
''' templates a data structure by traversing it and substituting for other data structures '''
try:
@ -346,7 +347,7 @@ def _template(basedir, varname, vars, lookup_fatal=True, depth=0, expand_lists=T
if isinstance(varname, basestring):
if '{{' in varname or '{%' in varname:
varname = template_from_string(basedir, varname, vars, fail_on_undefined)
varname = template_from_string(basedir, varname, vars, fail_on_undefined, lookups=lookups)
if not C.DEFAULT_LEGACY_PLAYBOOK_VARIABLES:
return varname
@ -461,7 +462,7 @@ def template_from_file(basedir, path, vars):
res = res + '\n'
return template(basedir, res, vars)
def template_from_string(basedir, data, vars, fail_on_undefined=False):
def template_from_string(basedir, data, vars, fail_on_undefined=False, lookups=True):
''' run a string through the (Jinja2) templating engine '''
def my_lookup(*args, **kwargs):
@ -504,7 +505,8 @@ def template_from_string(basedir, data, vars, fail_on_undefined=False):
else:
return data
t.globals['lookup'] = my_lookup
if lookups:
t.globals['lookup'] = my_lookup
try:
return t.render(vars)