mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-27 07:01:22 -07:00
dict2items filter
This commit is contained in:
parent
2e852fcd6d
commit
399cba1c84
1 changed files with 14 additions and 0 deletions
|
@ -488,6 +488,19 @@ def flatten(mylist, levels=None):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
def dict_to_list_of_dict_key_value_elements(mydict):
|
||||||
|
''' takes a dictionary and transforms it into a list of dictionaries,
|
||||||
|
with each having a 'key' and 'value' keys that correspond to the keys and values of the original '''
|
||||||
|
|
||||||
|
if not isinstance(mydict, MutableMapping):
|
||||||
|
raise AnsibleFilterError("dict2items requires a dictionary, got %s instead." % type(mydict))
|
||||||
|
|
||||||
|
ret = []
|
||||||
|
for key in mydict:
|
||||||
|
ret.append({'key': key, 'value': mydict[key]})
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
class FilterModule(object):
|
class FilterModule(object):
|
||||||
''' Ansible core jinja2 filters '''
|
''' Ansible core jinja2 filters '''
|
||||||
|
|
||||||
|
@ -574,4 +587,5 @@ class FilterModule(object):
|
||||||
'combine': combine,
|
'combine': combine,
|
||||||
'extract': extract,
|
'extract': extract,
|
||||||
'flatten': flatten,
|
'flatten': flatten,
|
||||||
|
'dict2items': dict_to_list_of_dict_key_value_elements,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue