mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-22 22:11:44 -07:00
Adds configurable jinja2 extension loading
Jinja extensions adds features to the jinja2 templating engine. This patch allows module loading for the templating engine vian an ansible.cfg configuration key (jinja_extensions). The default behaviour doesn't change (no module loading). Requested modules can be added coma separated in ansible.cfg Adds whitespace handling in jinja_extension config Added whitespace handling in jinja_extension configuration directive, so things stay safe if user adds spaces around comas in the directives list. Adds config example for jinja_extensions Added config example with multiple extentions for jinja_extensions
This commit is contained in:
parent
83ce1b2dc5
commit
1c22f2146e
3 changed files with 22 additions and 1 deletions
|
@ -313,7 +313,20 @@ def template_from_file(basedir, path, vars):
|
|||
from ansible import utils
|
||||
realpath = utils.path_dwim(basedir, path)
|
||||
loader=jinja2.FileSystemLoader([basedir,os.path.dirname(realpath)])
|
||||
environment = jinja2.Environment(loader=loader, trim_blocks=True)
|
||||
|
||||
'''
|
||||
if some extensions are set via jinja_extensions in ansible.cfg, we try
|
||||
to load them with the jinja environment
|
||||
'''
|
||||
jinja_exts = []
|
||||
if C.DEFAULT_JINA_EXTENSIONS:
|
||||
'''
|
||||
Let's make sure the configuration directive doesn't contain spaces
|
||||
and split extensions in an array
|
||||
'''
|
||||
jinja_exts = C.DEFAULT_JINA_EXTENSIONS.replace(" ", "").split(',')
|
||||
|
||||
environment = jinja2.Environment(loader=loader, trim_blocks=True, extensions=jinja_exts)
|
||||
for filter_plugin in utils.plugins.filter_loader.all():
|
||||
filters = filter_plugin.filters()
|
||||
if not isinstance(filters, dict):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue