mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-04 09:43:15 +00:00
dict2items filter
This commit is contained in:
@@ -488,6 +488,19 @@ def flatten(mylist, levels=None):
|
||||
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):
|
||||
''' Ansible core jinja2 filters '''
|
||||
|
||||
@@ -574,4 +587,5 @@ class FilterModule(object):
|
||||
'combine': combine,
|
||||
'extract': extract,
|
||||
'flatten': flatten,
|
||||
'dict2items': dict_to_list_of_dict_key_value_elements,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user