mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 15:06:26 +02:00
General code optimations and peertube optimation
This commit is contained in:
37
filter_plugins/redirect_filters.py
Normal file
37
filter_plugins/redirect_filters.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# roles/<your-role>/filter_plugins/redirect_filters.py
|
||||
from ansible.errors import AnsibleFilterError
|
||||
|
||||
class FilterModule(object):
|
||||
"""
|
||||
Custom filters for redirect domain mappings
|
||||
"""
|
||||
|
||||
def filters(self):
|
||||
return {
|
||||
"add_redirect_if_group": self.add_redirect_if_group,
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def add_redirect_if_group(redirect_list, group, source, target, group_names):
|
||||
"""
|
||||
Append {"source": source, "target": target} to *redirect_list*
|
||||
**only** if *group* is contained in *group_names*.
|
||||
|
||||
Usage in Jinja:
|
||||
{{ redirect_list
|
||||
| add_redirect_if_group('lam',
|
||||
'ldap.' ~ primary_domain,
|
||||
domains | get_domain('lam'),
|
||||
group_names) }}
|
||||
"""
|
||||
try:
|
||||
# Make a copy so we don’t mutate the original list in place
|
||||
redirects = list(redirect_list)
|
||||
|
||||
if group in group_names:
|
||||
redirects.append({"source": source, "target": target})
|
||||
|
||||
return redirects
|
||||
|
||||
except Exception as exc:
|
||||
raise AnsibleFilterError(f"add_redirect_if_group failed: {exc}")
|
Reference in New Issue
Block a user