mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 19:31:26 -07:00
Merge pull request #459 from dhozac/with_items-variable
Allow a variable in with_items
This commit is contained in:
commit
bd893b765b
3 changed files with 23 additions and 22 deletions
|
@ -201,7 +201,7 @@ def parse_json(data):
|
|||
|
||||
_LISTRE = re.compile(r"(\w+)\[(\d+)\]")
|
||||
|
||||
def varLookup(name, vars):
|
||||
def _varLookup(name, vars):
|
||||
''' find the contents of a possibly complex variable in vars. '''
|
||||
path = name.split('.')
|
||||
space = vars
|
||||
|
@ -223,6 +223,12 @@ def varLookup(name, vars):
|
|||
_KEYCRE = re.compile(r"\$(?P<complex>\{){0,1}((?(complex)[\w\.\[\]]+|\w+))(?(complex)\})")
|
||||
# if { -> complex if complex, allow . and need trailing }
|
||||
|
||||
def varLookup(varname, vars):
|
||||
m = _KEYCRE.search(varname)
|
||||
if not m:
|
||||
return None
|
||||
return _varLookup(m.group(2), vars)
|
||||
|
||||
def varReplace(raw, vars):
|
||||
'''Perform variable replacement of $vars
|
||||
|
||||
|
@ -245,7 +251,7 @@ def varReplace(raw, vars):
|
|||
# original)
|
||||
varname = m.group(2)
|
||||
|
||||
replacement = unicode(varLookup(varname, vars) or m.group())
|
||||
replacement = unicode(_varLookup(varname, vars) or m.group())
|
||||
|
||||
start, end = m.span()
|
||||
done.append(raw[:start]) # Keep stuff leading up to token
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue