mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #530 from dhozac/templates-vars
Allow variables in variables in templates
This commit is contained in:
commit
24b91169d9
1 changed files with 3 additions and 3 deletions
|
@ -279,13 +279,13 @@ def template_from_file(basedir, path, vars, setup_cache):
|
||||||
''' run a file through the templating engine '''
|
''' run a file through the templating engine '''
|
||||||
environment = jinja2.Environment(loader=jinja2.FileSystemLoader(basedir), trim_blocks=False)
|
environment = jinja2.Environment(loader=jinja2.FileSystemLoader(basedir), trim_blocks=False)
|
||||||
data = codecs.open(path_dwim(basedir, path), encoding="utf8").read()
|
data = codecs.open(path_dwim(basedir, path), encoding="utf8").read()
|
||||||
template = environment.from_string(data)
|
t = environment.from_string(data)
|
||||||
vars = vars.copy()
|
vars = vars.copy()
|
||||||
vars['hostvars'] = setup_cache
|
vars['hostvars'] = setup_cache
|
||||||
res = template.render(vars)
|
res = t.render(vars)
|
||||||
if data.endswith('\n') and not res.endswith('\n'):
|
if data.endswith('\n') and not res.endswith('\n'):
|
||||||
res = res + '\n'
|
res = res + '\n'
|
||||||
return res
|
return template(res, vars, setup_cache)
|
||||||
|
|
||||||
def parse_yaml(data):
|
def parse_yaml(data):
|
||||||
return yaml.load(data)
|
return yaml.load(data)
|
||||||
|
|
Loading…
Reference in a new issue