mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-22 22:11:44 -07: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:
parent
43f48a2e02
commit
9858b1f2f3
6 changed files with 51 additions and 98 deletions
|
@ -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'])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue