Combine lists of dicts (#32686)
* allow combine to take lists of dicts * updated as per feedback
This commit is contained in:
parent
9c629f8a1c
commit
ee80215fa9
1 changed files with 8 additions and 3 deletions
|
@ -322,14 +322,19 @@ def combine(*terms, **kwargs):
|
|||
if len(kwargs) > 1 or (len(kwargs) == 1 and 'recursive' not in kwargs):
|
||||
raise errors.AnsibleFilterError("'recursive' is the only valid keyword argument")
|
||||
|
||||
dicts = []
|
||||
for t in terms:
|
||||
if not isinstance(t, dict):
|
||||
if isinstance(t, MutableMapping):
|
||||
dicts.append(t)
|
||||
elif isinstance(t, list):
|
||||
dicts.append(combine(*t, **kwargs))
|
||||
else:
|
||||
raise errors.AnsibleFilterError("|combine expects dictionaries, got " + repr(t))
|
||||
|
||||
if recursive:
|
||||
return reduce(merge_hash, terms)
|
||||
return reduce(merge_hash, dicts)
|
||||
else:
|
||||
return dict(itertools.chain(*map(iteritems, terms)))
|
||||
return dict(itertools.chain(*map(iteritems, dicts)))
|
||||
|
||||
|
||||
def comment(text, style='plain', **kw):
|
||||
|
|
Loading…
Reference in a new issue