Files
computer-playbook/roles/sys-service/tasks/06_service.yml
kevinveenbirkenbachandClaude Opus 5 99f7e03845 feat(sys-service): carry unit ordering, an Install section and a user scope
The generic unit template could express neither an ordering dependency nor an Install section, so a role needing either shipped its own templates/systemctl.service.j2 and re-answered the daemon reload, the enable and the flush behaviour by hand.

Add After, Before, Wants, RemainAfterExit and a WantedBy driven Install section, all inert at their defaults, and route the unit path, its owner, become and the systemctl probes through a system_service_scope so a per-login unit lands under the user's own systemd directory.

00_core is gated on the system scope rather than only its prune and lockdown steps: it sets run_once_sys_service, so a user-scope caller running first would otherwise skip the lockdown for every system-scope role behind it in the same play.

Rendering the previous template against the same inputs drops no directive and adds none; the only difference is the blank line an empty directive used to leave behind.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-15 18:09:43 +02:00

48 lines
1.6 KiB
YAML

---
- name: 🔍 Resolve systemctl template source
set_fact:
system_service_template_src: >-
{{ lookup(
'first_found',
{
'files': [
'templates/systemctl@.service.j2',
'templates/systemctl.service.j2'
],
'paths': [
system_service_role_dir,
role_path
]
},
errors='strict'
) }}
- name: ✅ Ensure a systemctl template was found
assert:
that: system_service_template_src | length > 0
fail_msg: >-
Could not resolve any systemctl template. Looked in:
{{ system_service_role_dir }}/templates/ and {{ role_path }}/templates/.
when: MODE_ASSERT | bool
- name: "🔧 setup systemctl '{{ system_service_id }}'"
template: # nocheck: stack-host-template (per-host systemd service unit)
src: "{{ system_service_template_src }}"
dest: "{{ [ system_service_unit_dir, system_service_name ] | path_join }}"
owner: "{{ system_service_unit_owner }}"
group: "{{ system_service_unit_owner }}"
mode: "0644"
become: "{{ system_service_unit_become }}"
notify: "{{ 'reload-system-daemon' if system_service_is_template | bool else 'refresh-systemctl-service' }}"
- name: 🔄 refresh systemctl service when SYS_SERVICE_ALL_ENABLE
block:
- name: 🔄 reload system daemon
command: /bin/true
notify: reload-system-daemon
- name: 🔄 refresh systemctl service
command: /bin/true
notify: refresh-systemctl-service
when: not system_service_is_template | bool
when: system_service_force_flush_instant | bool