debian-setup/tasks/syncthing.yml

80 lines
2.2 KiB
YAML

---
- name: Disable system process
become: true
ansible.builtin.systemd:
name: syncthing@sonny
state: stopped
enabled: false
- name: Create Syncthing directories
become: true
ansible.builtin.file:
path: "{{ item.path }}"
owner: "{{ item.owner }}"
group: "{{ item.group }}"
mode: "0755"
state: directory
loop:
- path: "{{ syncthing_app_dir }}"
owner: root
group: root
- path: "{{ syncthing_app_dir }}/state"
owner: sonny
group: sonny
- path: "{{ syncthing_app_dir }}/nginx.conf.d"
owner: sonny
group: sonny
- name: Stop current containers
community.docker.docker_compose_v2:
project_src: "{{ syncthing_app_dir }}"
state: stopped
- name: Remove previous Syncthing configurations
become: true
ansible.builtin.file:
path: /home/sonny/.config/syncthing
state: absent
- name: Copy docker compose configuration
become: true
ansible.builtin.template:
src: "templates/syncthing/docker-compose.j2"
dest: "{{ syncthing_app_dir }}/docker-compose.yml"
owner: sonny
group: sonny
mode: "0755"
# The current configuration has the bare minimum options configured per element
# and relies on falling back to syncthing's defaults. This is because Syncthing
# overwrites the config file while the application is running,
# see https://forum.syncthing.net/t/manage-devices-and-folders-with-ansible/20078.
# Note that the config version should also be updated whenever the image tag is updated.
- name: Copy Syncthing configuration
become: true
ansible.builtin.template:
src: "templates/syncthing/config.j2"
dest: "{{ syncthing_app_dir }}/state/config.xml"
owner: sonny
group: sonny
mode: "0755"
- name: Copy NGINX configuration
become: true
ansible.builtin.template:
src: "templates/syncthing/nginx.j2"
dest: "{{ syncthing_app_dir }}/nginx.conf.d/default.conf"
owner: sonny
group: sonny
mode: "0755"
- name: Remove dangling containers
community.docker.docker_compose_v2:
project_src: "{{ syncthing_app_dir }}"
remove_orphans: true
state: stopped
- name: Start container
community.docker.docker_compose_v2:
project_src: "{{ syncthing_app_dir }}"
state: present