Commit 8e2528eb by Michael DeHaan

Merge pull request #384 from dne/template-fixes

Template fixes
parents 60d44e1a e4991d1a
...@@ -554,10 +554,9 @@ class Runner(object): ...@@ -554,10 +554,9 @@ class Runner(object):
copy_module = self._transfer_module(conn, tmp, 'copy') copy_module = self._transfer_module(conn, tmp, 'copy')
# template the source data locally # template the source data locally
source_data = codecs.open(utils.path_dwim(self.basedir, source), encoding="utf8").read()
resultant = ''
try: try:
resultant = utils.template(source_data, inject, self.setup_cache, no_engine=False) resultant = utils.template_from_file(utils.path_dwim(self.basedir, source),
inject, self.setup_cache, no_engine=False)
except Exception, e: except Exception, e:
return (host, False, dict(failed=True, msg=str(e)), '') return (host, False, dict(failed=True, msg=str(e)), '')
xfered = self._transfer_str(conn, tmp, 'source', resultant) xfered = self._transfer_str(conn, tmp, 'source', resultant)
......
...@@ -257,8 +257,8 @@ def varReplace(raw, vars): ...@@ -257,8 +257,8 @@ def varReplace(raw, vars):
def template(text, vars, setup_cache, no_engine=True): def template(text, vars, setup_cache, no_engine=True):
''' run a text buffer through the templating engine ''' ''' run a text buffer through the templating engine '''
vars = vars.copy() vars = vars.copy()
text = varReplace(unicode(text), vars)
vars['hostvars'] = setup_cache vars['hostvars'] = setup_cache
text = varReplace(unicode(text), vars)
if no_engine: if no_engine:
# used when processing include: directives so that Jinja is evaluated # used when processing include: directives so that Jinja is evaluated
# in a later context when more variables are available # in a later context when more variables are available
...@@ -273,7 +273,7 @@ def template(text, vars, setup_cache, no_engine=True): ...@@ -273,7 +273,7 @@ def template(text, vars, setup_cache, no_engine=True):
def double_template(text, vars, setup_cache): def double_template(text, vars, setup_cache):
return template(template(text, vars, setup_cache), vars, setup_cache) return template(template(text, vars, setup_cache), vars, setup_cache)
def template_from_file(path, vars, setup_cache, no_engine=False): def template_from_file(path, vars, setup_cache, no_engine=True):
''' run a file through the templating engine ''' ''' run a file through the templating engine '''
data = codecs.open(path, encoding="utf8").read() data = codecs.open(path, encoding="utf8").read()
return template(data, vars, setup_cache, no_engine=no_engine) return template(data, vars, setup_cache, no_engine=no_engine)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment