Custom Filter mapattributes

This commit is contained in:
Fabio Sinibaldi 2026-07-14 17:29:23 +02:00
parent dad4ec6928
commit 8d38f71eb5
2 changed files with 22 additions and 1 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
.DS_Store
ansible/playbooks/wg_clients
ansible/playbooks/wg_clients
ansible/playbooks/filter_plugins/__pycache__

View File

@ -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