mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-23 06:21:43 -07:00
This allows variable references in playbooks in a different way.
This commit is contained in:
parent
b5c9d5a59b
commit
90cce35919
3 changed files with 17 additions and 1 deletions
|
@ -30,6 +30,7 @@ import subprocess
|
|||
import datetime
|
||||
import pwd
|
||||
import ast
|
||||
import traceback
|
||||
|
||||
class Globals(object):
|
||||
|
||||
|
@ -304,6 +305,7 @@ def legacy_varReplace(basedir, raw, vars, lookup_fatal=True, depth=0, expand_lis
|
|||
|
||||
def template(basedir, varname, vars, lookup_fatal=True, depth=0, expand_lists=True, convert_bare=False, fail_on_undefined=False, filter_fatal=True):
|
||||
''' templates a data structure by traversing it and substituting for other data structures '''
|
||||
from ansible import utils
|
||||
|
||||
try:
|
||||
if convert_bare and isinstance(varname, basestring):
|
||||
|
@ -314,6 +316,12 @@ def template(basedir, varname, vars, lookup_fatal=True, depth=0, expand_lists=Tr
|
|||
if isinstance(varname, basestring):
|
||||
if '{{' in varname or '{%' in varname:
|
||||
varname = template_from_string(basedir, varname, vars, fail_on_undefined)
|
||||
|
||||
if (varname.startswith("{") and not varname.startswith("{{")) or varname.startswith("["):
|
||||
eval_results = utils.safe_eval(varname, locals=vars, include_exceptions=True)
|
||||
if eval_results[1] is None:
|
||||
varname = eval_results[0]
|
||||
|
||||
if not '$' in varname:
|
||||
return varname
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue