- action: syncthing_pre

- name: enforces service directories
  file:
    state: directory
    path: "{{ item }}"
    owner: "{{ syncthing_pre.user_group }}"
    mode: 0700
  loop:
    - "{{ syncthing_pre.config_dir }}"
    - "{{ syncthing_pre.data_dir }}"

- name: Install syncthing dependencies
  package:
    name: "{{ syncthing_pre.packages }}"

- name: Push syncthing gathering fact on clients
  template:
    src: syncthing.fact
    dest: /etc/ansible/facts.d/
    mode: 0500
    owner: root
  register: syncthing_gathering_fact

- name: reload ansible_local
  setup: filter=ansible_local
  when: syncthing_gathering_fact.changed

- action: syncthing_validate

- action: syncthing_init

- name: enforces config file
  template:
    src: config.xml
    dest: "{{ syncthing_pre.config_dir }}"
    owner: "{{ syncthing_pre.user_group }}"
    mode: 0400
  notify: restart syncthing

- name: start and enables service
  service:
    name: "{{ syncthing_pre.service }}"
    enabled: yes
    state: started