From b300aac551bc7092158655a94ef1cb1f5ff19594 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Wed, 2 May 2012 00:28:19 -0400 Subject: [PATCH] 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 --- CHANGELOG.md | 1 + lib/ansible/playbook.py | 2 +- lib/ansible/utils.py | 15 ++++++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bbca268e12..bf59ac3c879 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/ansible/playbook.py b/lib/ansible/playbook.py index 9f15784f1f4..d6e72251483 100644 --- a/lib/ansible/playbook.py +++ b/lib/ansible/playbook.py @@ -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): diff --git a/lib/ansible/utils.py b/lib/ansible/utils.py index a44f62d0e7e..92c321ce46e 100644 --- a/lib/ansible/utils.py +++ b/lib/ansible/utils.py @@ -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)