From 720e184f88aaa82a9ffaa9aeecda8da515060dba Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli Date: Fri, 3 Jul 2015 22:27:49 +0200 Subject: [PATCH] implement jinja2 header overrides --- lib/ansible/template/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/ansible/template/__init__.py b/lib/ansible/template/__init__.py index 8ce243f55f2..f10ea22fb5b 100644 --- a/lib/ansible/template/__init__.py +++ b/lib/ansible/template/__init__.py @@ -19,6 +19,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +import ast import re from jinja2 import Environment @@ -256,6 +257,17 @@ class Templar: overrides = JINJA2_ALLOWED_OVERRIDES.intersection(set(overrides)) myenv = self.environment.overlay(overrides) + # Get jinja env overrides from template + if data.startswith(JINJA2_OVERRIDE): + eol = data.find('\n') + line = data[len(JINJA2_OVERRIDE):eol] + data = data[eol+1:] + for pair in line.split(','): + (key,val) = pair.split(':') + key = key.strip() + if key in JINJA2_ALLOWED_OVERRIDES: + setattr(myenv, key, ast.literal_eval(val.strip())) + #FIXME: add tests myenv.filters.update(self._get_filters())