mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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):
|
if len(kwargs) > 1 or (len(kwargs) == 1 and 'recursive' not in kwargs):
|
||||||
raise errors.AnsibleFilterError("'recursive' is the only valid keyword argument")
|
raise errors.AnsibleFilterError("'recursive' is the only valid keyword argument")
|
||||||
|
|
||||||
|
dicts = []
|
||||||
for t in terms:
|
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))
|
raise errors.AnsibleFilterError("|combine expects dictionaries, got " + repr(t))
|
||||||
|
|
||||||
if recursive:
|
if recursive:
|
||||||
return reduce(merge_hash, terms)
|
return reduce(merge_hash, dicts)
|
||||||
else:
|
else:
|
||||||
return dict(itertools.chain(*map(iteritems, terms)))
|
return dict(itertools.chain(*map(iteritems, dicts)))
|
||||||
|
|
||||||
|
|
||||||
def comment(text, style='plain', **kw):
|
def comment(text, style='plain', **kw):
|
||||||
|
|
Loading…
Reference in a new issue