Include files are no longer to be considered Jinja2 templates, but individual THINGS
in included files can still be templated just like top level playbooks. Resolves some issues about statements being evaluated before facts were available
This commit is contained in:
parent
adca320490
commit
b300aac551
3 changed files with 12 additions and 6 deletions
|
@ -23,6 +23,7 @@ Ansible Changes By Release
|
|||
* service module works better on Ubuntu
|
||||
* git module now does resets and such to work more smoothly on updates
|
||||
* fix to internals of hacking/test-module development script
|
||||
* ansible-pull script and example playbook (extreme scaling, remediation)
|
||||
|
||||
0.3 "Baluchitherium" -- April 23, 2012
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ class PlayBook(object):
|
|||
include_vars[k] = v
|
||||
inject_vars = play_vars.copy()
|
||||
inject_vars.update(include_vars)
|
||||
included = utils.template_from_file(path, inject_vars, SETUP_CACHE)
|
||||
included = utils.template_from_file(path, inject_vars, SETUP_CACHE, no_engine=True)
|
||||
included = utils.parse_yaml(included)
|
||||
for x in included:
|
||||
if len(include_vars):
|
||||
|
|
|
@ -230,21 +230,26 @@ def varReplace(raw, vars):
|
|||
|
||||
return ''.join(done)
|
||||
|
||||
def template(text, vars, setup_cache):
|
||||
def template(text, vars, setup_cache, no_engine=False):
|
||||
''' run a text buffer through the templating engine '''
|
||||
vars = vars.copy()
|
||||
text = varReplace(str(text), vars)
|
||||
vars['hostvars'] = setup_cache
|
||||
template = jinja2.Template(text)
|
||||
return template.render(vars)
|
||||
if no_engine:
|
||||
# used when processing include: directives so that Jinja is evaluated
|
||||
# in a later context when more variables are available
|
||||
return text
|
||||
else:
|
||||
template = jinja2.Template(text)
|
||||
return template.render(vars)
|
||||
|
||||
def double_template(text, vars, setup_cache):
|
||||
return template(template(text, vars, setup_cache), vars, setup_cache)
|
||||
|
||||
def template_from_file(path, vars, setup_cache):
|
||||
def template_from_file(path, vars, setup_cache, no_engine=False):
|
||||
''' run a file through the templating engine '''
|
||||
data = file(path).read()
|
||||
return template(data, vars, setup_cache)
|
||||
return template(data, vars, setup_cache, no_engine=no_engine)
|
||||
|
||||
def parse_yaml(data):
|
||||
return yaml.load(data)
|
||||
|
|
Loading…
Reference in a new issue