--- - name: Check if service is already running ansible.builtin.command: cmd: "machinectl shell {{ service_name }}@ /bin/bash -c 'systemctl --user is-active {{ systemd_service_name }}' | grep -qv inactive" register: service_status ignore_errors: yes - name: Enable and start the main service ansible.builtin.command: cmd: "machinectl shell {{ service_name }}@ /bin/bash -c 'systemctl --user daemon-reload && systemctl --user start {{ systemd_service_name }}'" become: yes when: service_status.rc != 0 and (quadlet_files_copied.changed or force_systemd_restart) - name: Restart the main service ansible.builtin.command: cmd: "machinectl shell {{ service_name }}@ /bin/bash -c 'systemctl --user daemon-reload && systemctl --user restart {{ systemd_service_name }}'" become: yes when: service_status.rc == 0 and (quadlet_files_copied.changed or force_systemd_restart)