mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-28 11:10:21 -07:00
Merge pull request #1683 from bcoca/template_override
Template override
This commit is contained in:
commit
dbf5a57a5a
2 changed files with 21 additions and 1 deletions
|
@ -31,7 +31,7 @@ import pwd
|
||||||
# TODO: refactor this file
|
# TODO: refactor this file
|
||||||
|
|
||||||
_LISTRE = re.compile(r"(\w+)\[(\d+)\]")
|
_LISTRE = re.compile(r"(\w+)\[(\d+)\]")
|
||||||
|
JINJA2_OVERRIDE='#jinja2:'
|
||||||
|
|
||||||
def _varFindLimitSpace(basedir, vars, space, part, depth):
|
def _varFindLimitSpace(basedir, vars, space, part, depth):
|
||||||
''' limits the search space of space to part
|
''' limits the search space of space to part
|
||||||
|
@ -275,6 +275,16 @@ def template_from_file(basedir, path, vars):
|
||||||
raise errors.AnsibleError("unable to process as utf-8: %s" % realpath)
|
raise errors.AnsibleError("unable to process as utf-8: %s" % realpath)
|
||||||
except:
|
except:
|
||||||
raise errors.AnsibleError("unable to read %s" % realpath)
|
raise errors.AnsibleError("unable to read %s" % realpath)
|
||||||
|
|
||||||
|
# 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(':')
|
||||||
|
setattr(environment,key.strip(),val.strip())
|
||||||
|
|
||||||
t = environment.from_string(data)
|
t = environment.from_string(data)
|
||||||
vars = vars.copy()
|
vars = vars.copy()
|
||||||
try:
|
try:
|
||||||
|
|
10
test/jinja2_overrides.tpl
Normal file
10
test/jinja2_overrides.tpl
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#jinja2: variable_end_string: @@, variable_start_string: @@
|
||||||
|
|
||||||
|
{% raw %}
|
||||||
|
if this succeeds you should see '{{ ansible_hostname }}' with the hostname on the line above
|
||||||
|
if this fails you should see '@@ ansible_hostname @@' with the hostname on the line beneath
|
||||||
|
{% endraw %}
|
||||||
|
|
||||||
|
@@ ansible_hostname @@
|
||||||
|
{{ ansible_hostname }}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue