1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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:
Michael DeHaan 2012-05-02 00:28:19 -04:00
parent adca320490
commit b300aac551
3 changed files with 12 additions and 6 deletions

View file

@ -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

View file

@ -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):

View file

@ -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)