mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-22 22:11:44 -07:00
complex_arg templating should be smarter. Make it so!
This commit is contained in:
parent
ee4a0fc6a0
commit
224e20ca60
2 changed files with 24 additions and 11 deletions
|
@ -266,9 +266,16 @@ def legacy_varReplace(basedir, raw, vars, lookup_fatal=True, depth=0, expand_lis
|
|||
|
||||
return ''.join(done)
|
||||
|
||||
def template(basedir, varname, vars, lookup_fatal=True, depth=0, expand_lists=True):
|
||||
# TODO: varname is misnamed here
|
||||
|
||||
def template(basedir, varname, vars, lookup_fatal=True, depth=0, expand_lists=True, convert_bare=False):
|
||||
''' templates a data structure by traversing it and substituting for other data structures '''
|
||||
|
||||
if convert_bare and isinstance(varname, basestring):
|
||||
first_part = varname.split(".")[0].split("[")[0]
|
||||
if first_part in vars and '{{' not in varname and '$' not in varname:
|
||||
varname = "{{%s}}" % varname
|
||||
|
||||
if isinstance(varname, basestring):
|
||||
if '{{' in varname or '{%' in varname:
|
||||
varname = template_from_string(basedir, varname, vars)
|
||||
|
@ -439,7 +446,7 @@ def template_from_file(basedir, path, vars):
|
|||
|
||||
def template_from_string(basedir, data, vars):
|
||||
''' run a file through the (Jinja2) templating engine '''
|
||||
|
||||
|
||||
try:
|
||||
if type(data) == str:
|
||||
data = unicode(data, 'utf-8')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue