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
|
||||
|
||||
|
||||
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,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue