Refactor alarm composer and sys-service handling:

- Introduce dynamic SYSTEMCTL_ALARM_COMPOSER_SUBSERVICES based on Mailu token and MODE_RESET
- Prevent inclusion of sys-ctl-alm-email when disabled
- Add system_service_is_template flag to avoid state-setting on template services
- Update notifications to reload daemon for @ template units
- Align msmtp execution conditions

See: https://chatgpt.com/share/692c7a71-afcc-800f-8aba-6800a042ce3b
This commit is contained in:
2025-11-30 18:10:30 +01:00
parent 5a523cfe24
commit e53abbec3b
6 changed files with 19 additions and 14 deletions

View File

@@ -1,9 +1,7 @@
- name: "Include dependent services for '{{ system_service_id }}'"
include_role:
name: '{{ item }}'
loop:
- sys-ctl-alm-telegram
- sys-ctl-alm-email
loop: '{{ SYSTEMCTL_ALARM_COMPOSER_SUBSERVICES }}'
vars:
flush_handlers: true
system_service_timer_enabled: false

View File

@@ -1,7 +1,16 @@
system_service_id: sys-ctl-alm-compose@
SYSTEMCTL_ALARM_COMPOSER_SUBSERVICES:
SYSTEMCTL_ALARM_COMPOSER_SUBSERVICES_BASE:
- 'sys-ctl-alm-email'
- 'sys-ctl-alm-telegram'
SYSTEMCTL_ALARM_EMAIL_ENABLED: "{{ users['no-reply'].mailu_token | default(false) and not MODE_RESET }}"
SYSTEMCTL_ALARM_COMPOSER_SUBSERVICES: >-
{{
SYSTEMCTL_ALARM_COMPOSER_SUBSERVICES_BASE
if SYSTEMCTL_ALARM_EMAIL_ENABLED else
SYSTEMCTL_ALARM_COMPOSER_SUBSERVICES_BASE | reject('equalto', 'sys-ctl-alm-email') | list
}}
SYSTEMCTL_ALARM_COMPOSER_DUMMY_MESSAGE: "[Info] Dummy Message: No Failure; Ansible is initializing {{ SOFTWARE_NAME }} on {{ inventory_hostname }}."

View File

@@ -12,7 +12,7 @@
src: "{{ system_service_script_src }}"
dest: "{{ [system_service_script_dir, (system_service_script_src | basename | regex_replace('\\.j2$', ''))] | path_join }}"
mode: "0755"
notify: refresh systemctl service # Just refresh service for testing that script is working in debug mode. In productive due to async it shouldn't make a difference
notify: "{{ 'reload system daemon' if system_service_is_template | bool else 'refresh systemctl service' }}"
when: system_service_script_src.endswith('.j2')
- name: "copy raw file"
@@ -21,5 +21,5 @@
dest: "{{ [system_service_script_dir, (system_service_script_src | basename)] | path_join }}"
mode: "0755"
when: not system_service_script_src.endswith('.j2')
notify: refresh systemctl service # Just refresh service for testing that script is working in debug mode. In productive due to async it shouldn't make a difference
notify: "{{ 'reload system daemon' if system_service_is_template | bool else 'refresh systemctl service' }}"
when: system_service_copy_files | bool

View File

@@ -24,10 +24,6 @@
{{ system_service_role_dir }}/templates/ and {{ role_path }}/templates/.
when: MODE_ASSERT | bool
- name: Flag whether @-template is used
set_fact:
system_service_uses_at: "{{ system_service_id.endswith('@') }}"
- name: "setup systemctl '{{ system_service_id }}'"
template:
src: "{{ system_service_template_src }}"
@@ -35,7 +31,7 @@
owner: root
group: root
mode: '0644'
notify: "{{ 'reload system daemon' if system_service_uses_at else 'refresh systemctl service' }}"
notify: "{{ 'reload system daemon' if system_service_is_template | bool else 'refresh systemctl service' }}"
- name: refresh systemctl service when SYS_SERVICE_ALL_ENABLE
block:
@@ -45,6 +41,6 @@
- name: refresh systemctl service
command: /bin/true
notify: refresh systemctl service
when: not system_service_uses_at
when: not system_service_is_template | bool
when: system_service_force_flush | bool

View File

@@ -1,5 +1,8 @@
UNIT_SUFFIX_REMOVER_PACKAGE: "unsure"
# meta
system_service_name: "{{ system_service_id | get_service_name(SOFTWARE_NAME) }}"
system_service_is_template: "{{ system_service_id.endswith('@') }}"
## Paths
system_service_role_name: "{{ system_service_id | regex_replace('@','') }}"

View File

@@ -2,6 +2,5 @@
include_tasks: 01_core.yml
when:
- run_once_sys_svc_msmtp is not defined or run_once_sys_svc_msmtp is false
# Just execute when mailu_token is defined
- users['no-reply'].mailu_token is defined
- not MODE_RESET | bool
- not MODE_RESET | bool