mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00:00
Enable imports to work on a snippet based system, allowing for instance a library of common EC2 functions
to be reused between modules. See library/system/service and library/system/ping for initial examples. Can work the old way to just import 'basic', or can import the new way to import multiple pieces of code from module_utils/.
This commit is contained in:
@@ -462,7 +462,7 @@ def template_from_file(basedir, path, vars):
|
||||
res = res + '\n'
|
||||
return template(basedir, res, vars)
|
||||
|
||||
def template_from_string(basedir, data, vars, fail_on_undefined=False, lookups=True):
|
||||
def template_from_string(basedir, data, vars, fail_on_undefined=False, lookups=True, filters=True):
|
||||
''' run a string through the (Jinja2) templating engine '''
|
||||
|
||||
def my_lookup(*args, **kwargs):
|
||||
@@ -472,7 +472,9 @@ def template_from_string(basedir, data, vars, fail_on_undefined=False, lookups=T
|
||||
if type(data) == str:
|
||||
data = unicode(data, 'utf-8')
|
||||
environment = jinja2.Environment(trim_blocks=True, undefined=StrictUndefined, extensions=_get_extensions())
|
||||
environment.filters.update(_get_filters())
|
||||
|
||||
if filters:
|
||||
environment.filters.update(_get_filters())
|
||||
|
||||
if '_original_file' in vars:
|
||||
basedir = os.path.dirname(vars['_original_file'])
|
||||
|
||||
Reference in New Issue
Block a user