Added get_service_name

This commit is contained in:
Kevin Veen-Birkenbach 2025-08-18 22:10:52 +02:00
parent dc0bb555c1
commit 4a600ac531
No known key found for this signature in database
GPG Key ID: 44D8F11FD62F878E
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}

View File

@ -1,5 +1,4 @@
- name: Include dependency 'sys-ctl-hlth-msmtp'
include_role:
- include_role:
name: sys-ctl-hlth-msmtp
when: run_once_sys_ctl_hlth_msmtp is not defined