mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Undefined Jinja2 statements are returned as they originally are so you can tell there are things to
correct.
This commit is contained in:
parent
b82cda646d
commit
38c2b14339
1 changed files with 7 additions and 1 deletions
|
@ -403,11 +403,17 @@ def _get_filter_plugins():
|
||||||
FILTER_PLUGINS.update(filters)
|
FILTER_PLUGINS.update(filters)
|
||||||
return FILTER_PLUGINS
|
return FILTER_PLUGINS
|
||||||
|
|
||||||
|
class J2Undefined(jinja2.runtime.Undefined):
|
||||||
|
def __str__(self):
|
||||||
|
return "{{ %s }}" % self._undefined_name
|
||||||
|
def __unicode__(self):
|
||||||
|
return "{{ %s }}" % self._undefined_name
|
||||||
|
|
||||||
def template_from_string(basedir, data, vars):
|
def template_from_string(basedir, data, vars):
|
||||||
''' run a file through the (Jinja2) templating engine '''
|
''' run a file through the (Jinja2) templating engine '''
|
||||||
if type(data) == str:
|
if type(data) == str:
|
||||||
data = unicode(data, 'utf-8')
|
data = unicode(data, 'utf-8')
|
||||||
environment = jinja2.Environment(trim_blocks=True)
|
environment = jinja2.Environment(trim_blocks=True, undefined=J2Undefined)
|
||||||
environment.filters.update(_get_filter_plugins())
|
environment.filters.update(_get_filter_plugins())
|
||||||
# TODO: may need some way of using lookup plugins here seeing we aren't calling
|
# TODO: may need some way of using lookup plugins here seeing we aren't calling
|
||||||
# the legacy engine, lookup() as a function, perhaps?
|
# the legacy engine, lookup() as a function, perhaps?
|
||||||
|
|
Loading…
Reference in a new issue