--- - 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] Disable and stop service: syncthing-{{ services.syncthing.user }}" service: name: "syncthing-{{ syncthing.user }}" enabled: yes state: stopped when: - ansible_service_mgr == "openrc" - name: "[systemd] Disable and stop service: syncthing" environment: XDG_RUNTIME_DIR: "{{ xdg_runtime_dir }}" systemd: name: syncthing scope: user enabled: no state: stopped become: true become_user: "{{ services.syncthing.user }}" when: - ansible_service_mgr == "systemd" - name: "[Alpine] Remove package: syncthing" apk: name: syncthing state: absent when: - ansible_distribution == "Alpine" - services.syncthing.enable is false - name: "[Archlinux] Remove package: syncthing" pacman: name: syncthing state: absent when: - ansible_distribution == "Archlinux" - services.syncthing.enable is false - name: "Delete leftovers" file: path: "{{ item }}" state: absent with_items: - "/etc/init.d/syncthing-{{ services.syncthing.user }}" - name: "[nftables] Delete rule for: syncthing" file: path: /etc/nftables.d/syncthing.nft state: absent notify: "Restart nftables" - name: "Delete nginx vhost for: syncthing" file: path: /etc/nginx/conf.d/syncthing.conf state: absent notify: "Restart nginx"