mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-26 21:45:20 +02:00
Added get_service_name
This commit is contained in:
parent
dc0bb555c1
commit
4a600ac531
25
filter_plugins/get_service_name.py
Normal file
25
filter_plugins/get_service_name.py
Normal 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}
|
@ -6,5 +6,5 @@
|
||||
- include_role:
|
||||
name: sys-systemctl
|
||||
vars:
|
||||
systemctl_on_calendar: "{{ SYS_SCHEDULE_HEALTH_MSMTP }}"
|
||||
systemctl_on_calendar: "{{ SYS_SCHEDULE_HEALTH_MSMTP }}"
|
||||
systemctl_timer_enabled: true
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user