diff --git a/.gitignore b/.gitignore index 5bcca5c..6e9bb20 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store -ansible/playbooks/wg_clients \ No newline at end of file +ansible/playbooks/wg_clients +ansible/playbooks/filter_plugins/__pycache__ \ No newline at end of file diff --git a/ansible/playbooks/filter_plugins/mapattributes.py b/ansible/playbooks/filter_plugins/mapattributes.py new file mode 100644 index 0000000..e663e17 --- /dev/null +++ b/ansible/playbooks/filter_plugins/mapattributes.py @@ -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