--- - name: "Enable linger for user: {{ services.syncthing.user }}" command: "loginctl enable-linger {{ services.syncthing.user }}" changed_when: false when: - ansible_service_mgr == "systemd" - services.syncthing.user is defined - name: "Find uid of user: {{ services.rest_server.user }}" command: "id -u {{ services.syncthing.user }}" register: userId check_mode: no # Run even in check mode, otherwise the playbook fails with --check. changed_when: false when: - ansible_service_mgr == "systemd" - services.syncthing.user is defined - name: "Determine XDG_RUNTIME_DIR" set_fact: xdg_runtime_dir: "/run/user/{{ userId.stdout }}" changed_when: false when: - ansible_service_mgr == "systemd" - name: "[OpenRC] Enable and start service: syncthing-{{ services.syncthing.user }}" service: name: "syncthing-{{ services.syncthing.user }}" enabled: yes state: started when: - ansible_service_mgr == "openrc" - name: "[systemd] Enable and start service: syncthing" environment: XDG_RUNTIME_DIR: "{{ xdg_runtime_dir }}" systemd: name: syncthing scope: user enabled: yes state: started become: true become_user: "{{ services.syncthing.user }}" when: - ansible_service_mgr == "systemd"