Custom Filter mapattributes
This commit is contained in:
parent
dad4ec6928
commit
8d38f71eb5
|
|
@ -1,2 +1,3 @@
|
||||||
.DS_Store
|
.DS_Store
|
||||||
ansible/playbooks/wg_clients
|
ansible/playbooks/wg_clients
|
||||||
|
ansible/playbooks/filter_plugins/__pycache__
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Source - https://stackoverflow.com/a/57665825
|
||||||
|
# Posted by Rabin, modified by community. See post 'Timeline' for change history
|
||||||
|
# Retrieved 2026-07-14, License - CC BY-SA 4.0
|
||||||
|
|
||||||
|
#!/usr/bin/env python
|
||||||
|
class FilterModule(object):
|
||||||
|
def filters(self):
|
||||||
|
return { 'mapattributes': self.mapattributes }
|
||||||
|
|
||||||
|
def mapattributes(self, list_of_dicts, list_of_keys):
|
||||||
|
l = []
|
||||||
|
for di in list_of_dicts:
|
||||||
|
newdi = { }
|
||||||
|
for key in list_of_keys:
|
||||||
|
# newdi[key] = di[key]
|
||||||
|
if di.get(key, None) != None:
|
||||||
|
newdi[key] = di[key]
|
||||||
|
|
||||||
|
l.append(newdi)
|
||||||
|
return l
|
||||||
Loading…
Reference in New Issue