Added get_service_name

This commit is contained in:
2025-08-18 22:10:52 +02:00
parent dc0bb555c1
commit 4a600ac531
3 changed files with 27 additions and 3 deletions

View File

@@ -0,0 +1,25 @@
# filter_plugins/get_service_name.py
"""
Custom Ansible filter to build a systemctl unit name (always lowercase).
Rules:
- If `systemctl_id` ends with '@': drop the '@' and return
"{systemctl_id_without_at}.{software_name}@.{suffix}".
- Else: return "{systemctl_id}{software_name}.{suffix}".
"""
def get_service_name(systemctl_id, software_name, suffix="service"):
sid = str(systemctl_id).strip().lower()
sw = str(software_name).strip().lower()
sfx = str(suffix).strip().lower()
if sid.endswith('@'):
base = sid[:-1] # drop the trailing '@'
return f"{base}.{sw}@.{sfx}"
else:
return f"{sid}{sw}.{sfx}"
class FilterModule(object):
def filters(self):
return {"get_service_name": get_service_name}