enable syncthing only if necessary

This commit is contained in:
Pim Kunis 2022-12-27 18:12:17 +01:00
parent 76d3b54c8d
commit cc13808081

View file

@ -10,17 +10,22 @@
template: template:
src: "{{ role_path }}/templates/config.xml.j2" src: "{{ role_path }}/templates/config.xml.j2"
dest: ~/.config/syncthing/config.xml dest: ~/.config/syncthing/config.xml
register: config
- name: Copy Syncthing private key - name: Copy Syncthing private key
copy: copy:
src: "{{ role_path }}/files/key.pem" src: "{{ role_path }}/files/key.pem"
dest: ~/.config/syncthing/key.pem dest: ~/.config/syncthing/key.pem
register: private_key
- name: Copy Syncthing certificate - name: Copy Syncthing certificate
copy: copy:
src: "{{ role_path }}/files/cert.pem" src: "{{ role_path }}/files/cert.pem"
dest: ~/.config/syncthing/cert.pem dest: ~/.config/syncthing/cert.pem
register: certificate
- name: Enable Syncthing - name: Enable Syncthing
become: true become: true
systemd: systemd:
enabled: true enabled: true
name: "syncthing@{{ ansible_user_id }}" name: "syncthing@{{ ansible_user_id }}"
state: restarted state: "{{ state }}"
vars:
state: "{{ 'restarted' if config.changed or private_key.changed or certificate.changed else 'started' }}"