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

pull/4674/head
James Tanner 11 years ago
parent baccced4d4
commit 9b1fe455c6

@ -353,7 +353,7 @@ class PlayBook(object):
else: else:
name = task.name 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: if hasattr(self.callbacks, 'skip_task') and self.callbacks.skip_task:
ansible.callbacks.set_task(self.callbacks, None) ansible.callbacks.set_task(self.callbacks, None)
ansible.callbacks.set_task(self.runner_callbacks, None) ansible.callbacks.set_task(self.runner_callbacks, None)

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

Loading…
Cancel
Save