Fix some subtle things that were keeping 'hostvars' from being usable in templates.

This commit is contained in:
Michael DeHaan 2012-07-20 12:34:26 -04:00
parent 2b6d8a8be5
commit 2d06ee4c0d
2 changed files with 14 additions and 13 deletions

View file

@ -211,9 +211,7 @@ def template_from_file(basedir, path, vars):
environment = jinja2.Environment(loader=jinja2.FileSystemLoader(basedir), trim_blocks=False)
data = codecs.open(path_dwim(basedir, path), encoding="utf8").read()
t = environment.from_string(data)
# FIXME: possibly a bit inefficient here, do this in runner code
vars = vars.copy()
vars['hostvars'] = vars.get('setup_cache',{})
res = t.render(vars)
if data.endswith('\n') and not res.endswith('\n'):
res = res + '\n'