--- - name: "🔧 Enable systemctl service" systemd: name: "{{ system_service_name }}" scope: "{{ system_service_scope }}" enabled: true daemon_reload: true become: "{{ system_service_unit_become }}" # rationale: async; opt-out per caller, a role that reads the unit state sets system_service_force_linear_sync async: "{{ system_service_async }}" poll: "{{ system_service_poll }}" - name: "🔧 Set systemctl service state" systemd: name: "{{ system_service_name }}" scope: "{{ system_service_scope }}" state: "{{ system_service_state }}" become: "{{ system_service_unit_become }}" # rationale: async; the Result gate below only runs meaningfully for callers that set system_service_force_linear_sync async: "{{ system_service_async }}" poll: "{{ system_service_poll }}" when: not (system_service_suppress_flush | bool) register: systemd_set_state failed_when: false - name: 🔍 sys-service | Read unit Result (oneshot-safe) ansible.builtin.command: argv: "{{ system_service_systemctl_show + ['Result', system_service_name] }}" register: system_service_result changed_when: false failed_when: false - name: 🔍 sys-service | Read unit ExecMainStatus (oneshot-safe) ansible.builtin.command: argv: "{{ system_service_systemctl_show + ['ExecMainStatus', system_service_name] }}" register: system_service_exec_status changed_when: false failed_when: false - name: 🐛 sys-service | Show diagnostics on failure ansible.builtin.include_tasks: "{{ role_path }}/tasks/utils/debug.yml" vars: system_service_debug_unit: "{{ system_service_name }}" system_service_debug_context_lines: - "system_service_id={{ system_service_id }}" - "system_service_name={{ system_service_name }}" - "system_service_state={{ system_service_state | default('') }}" - "system_service_result={{ system_service_result.stdout | default('') | trim }}" - "system_service_exec_status={{ system_service_exec_status.stdout | default('') | trim }}" - "systemd_set_state={{ systemd_set_state | to_nice_json }}" system_service_debug_fail: true system_service_debug_fail_message: >- Unable to start service {{ system_service_name }}. See shared service diagnostics above. when: - not (system_service_suppress_flush | bool) - (systemd_set_state.failed | default(false) | bool) or (system_service_state != omit and ( (system_service_result.stdout | default('') | trim) not in ['success', ''] or (system_service_exec_status.stdout | default('') | trim) not in ['0', '']))