aboutsummaryrefslogtreecommitdiffstats
path: root/roles/setup_syncthing
diff options
context:
space:
mode:
Diffstat (limited to 'roles/setup_syncthing')
-rw-r--r--roles/setup_syncthing/tasks/main.yml131
-rw-r--r--roles/setup_syncthing/templates/syncthing.service25
-rw-r--r--roles/setup_syncthing/vars/main.yml32
3 files changed, 188 insertions, 0 deletions
diff --git a/roles/setup_syncthing/tasks/main.yml b/roles/setup_syncthing/tasks/main.yml
new file mode 100644
index 0000000..431f27f
--- /dev/null
+++ b/roles/setup_syncthing/tasks/main.yml
@@ -0,0 +1,131 @@
+
+# =========================================================================== #
+# __ __ __ _
+# _________ / /__ _______ ______ _____/ /_/ /_ (_)___ ____ _
+# / ___/ __ \/ / _ \ / ___/ / / / __ \/ ___/ __/ __ \/ / __ \/ __ `/
+# / / / /_/ / / __/ (__ ) /_/ / / / / /__/ /_/ / / / / / / / /_/ /
+# /_/ \____/_/\___(_) /____/\__, /_/ /_/\___/\__/_/ /_/_/_/ /_/\__, /
+# /____/ /____/
+#
+# =========================================================================== #
+
+---
+- name: Add group syncthing
+ group:
+ name: "{{ syncthing_user }}"
+ state: present
+
+- name: Add user syncthing
+ user:
+ name: "{{ syncthing_user }}"
+ comment: "{{ syncthing_group }}"
+ group: "{{ syncthing_group }}"
+
+- name: Create syncthing bin directory
+ file:
+ path: "{{ syncthing_bin_directory }}"
+ state: directory
+ owner: "{{ syncthing_user }}"
+ group: "{{ syncthing_group }}"
+ mode: 0755
+ recurse: True
+
+- name: Create syncthing sync directory
+ file:
+ path: "{{ syncthing_files_directory }}"
+ state: directory
+ owner: "{{ syncthing_user }}"
+ group: "{{ syncthing_group }}"
+ mode: 0755
+ recurse: True
+
+- name: Download and extract syncthing archive
+ become_user: syncthing
+ unarchive:
+ src: "{{ syncthing_download_url }}/{{ syncthing_version }}/syncthing-{{ syncthing_os }}-{{ syncthing_architecture }}-{{ syncthing_version }}.tar.gz"
+ dest: "{{ syncthing_download_directory }}"
+ remote_src: yes
+
+- name: Copy syncthing bin
+ copy:
+ src: "{{ syncthing_download_directory }}/syncthing-{{ syncthing_os }}-{{ syncthing_architecture }}-{{ syncthing_version }}/syncthing"
+ remote_src: yes
+ dest: "{{ syncthing_bin_directory }}"
+ owner: "{{ syncthing_user }}"
+ group: "{{ syncthing_group }}"
+ mode: 0744
+
+- name: Copy syncthing systemd unit
+ template:
+ src: "{{ syncthing_daemon_unit }}.service"
+ dest: "{{ g_systemd_unit_directory }}"
+ owner: root
+ group: root
+ mode: 0644
+
+- name: Start syncthing systemd unit
+ systemd:
+ name: "{{ syncthing_daemon_unit }}"
+ state: restarted
+ daemon_reload: yes
+
+- name: Stop syncthing systemd unit
+ systemd:
+ name: "{{ syncthing_daemon_unit }}"
+ state: stopped
+
+- name: Config networking
+ xml:
+ path: "{{ syncthing_config_directory }}/config.xml"
+ xpath: /configuration/gui/address
+ value: "0.0.0.0:{{ g_port_syncthing_gui }}"
+
+- name: Config clear directory path
+ xml:
+ path: "{{ syncthing_config_directory }}/config.xml"
+ xpath: "/configuration/folder/@path"
+ state: present
+
+- name: Config directory path
+ replace:
+ path: "{{ syncthing_config_directory }}/config.xml"
+ regexp: "path=\"\""
+ replace: "path=\"{{ syncthing_files_directory }}\""
+
+- name: Config disable relay
+ xml:
+ path: "{{ syncthing_config_directory }}/config.xml"
+ xpath: /configuration/options/relaysEnabled
+ value: "{{ syncthing_b_relays }}"
+
+- name: Config disable global announcements
+ xml:
+ path: "{{ syncthing_config_directory }}/config.xml"
+ xpath: /configuration/options/globalAnnounceEnabled
+ value: "{{ syncthing_b_global_announcements }}"
+
+- name: Config disable nat
+ xml:
+ path: "{{ syncthing_config_directory }}/config.xml"
+ xpath: /configuration/options/natEnabled
+ value: "{{ syncthing_b_nat }}"
+
+- name: Config disable crash reporting
+ xml:
+ path: "{{ syncthing_config_directory }}/config.xml"
+ xpath: /configuration/options/crashReportingEnabled
+ value: "{{ syncthing_b_crash_reporting }}"
+
+- name: Config disable browser autostart
+ xml:
+ path: "{{ syncthing_config_directory }}/config.xml"
+ xpath: /configuration/options/startBrowser
+ value: "{{ syncthing_b_start_browser }}"
+
+- name: Start and enable syncthing systemd unit
+ systemd:
+ name: "{{ syncthing_daemon_unit }}"
+ state: restarted
+ daemon_reload: yes
+ enabled: yes
+
diff --git a/roles/setup_syncthing/templates/syncthing.service b/roles/setup_syncthing/templates/syncthing.service
new file mode 100644
index 0000000..fe4c429
--- /dev/null
+++ b/roles/setup_syncthing/templates/syncthing.service
@@ -0,0 +1,25 @@
+
+# =========================================================================== #
+# _ __ __ __ _
+# __ ______ (_) /_ _______ ______ _____/ /_/ /_ (_)___ ____ _
+# / / / / __ \/ / __/ / ___/ / / / __ \/ ___/ __/ __ \/ / __ \/ __ `/
+# / /_/ / / / / / /__ (__ ) /_/ / / / / /__/ /_/ / / / / / / / /_/ /
+# \__,_/_/ /_/_/\__(_) /____/\__, /_/ /_/\___/\__/_/ /_/_/_/ /_/\__, /
+# /____/ /____/
+#
+# =========================================================================== #
+
+[Unit]
+Description=Synchronization service for files
+
+[Service]
+Type=simple
+User={{ syncthing_user }}
+Group={{ syncthing_group }}
+WorkingDirectory={{ syncthing_files_directory }}
+ExecStart={{ syncthing_bin_directory }}/syncthing
+ExecStop=/bin/kill -s HUP $MAINPID
+RuntimeDirectoryMode=0700
+
+[Install]
+WantedBy=default.target
diff --git a/roles/setup_syncthing/vars/main.yml b/roles/setup_syncthing/vars/main.yml
new file mode 100644
index 0000000..16eb97f
--- /dev/null
+++ b/roles/setup_syncthing/vars/main.yml
@@ -0,0 +1,32 @@
+
+# =========================================================================== #
+# __ __ _
+# _ ______ ___________ _______ ______ _____/ /_/ /_ (_)___ ____ _
+# | | / / __ `/ ___/ ___/ / ___/ / / / __ \/ ___/ __/ __ \/ / __ \/ __ `/
+# | |/ / /_/ / / (__ ) (__ ) /_/ / / / / /__/ /_/ / / / / / / / /_/ /
+# |___/\__,_/_/ /____(_) /____/\__, /_/ /_/\___/\__/_/ /_/_/_/ /_/\__, /
+# /____/ /____/
+#
+# =========================================================================== #
+
+---
+syncthing_user: syncthing
+syncthing_user_comment: handles syncthing service
+syncthing_group: syncthing
+syncthing_daemon_unit: syncthing
+
+syncthing_os: linux
+syncthing_version: v1.6.1
+syncthing_architecture: arm
+syncthing_download_url: https://github.com/syncthing/syncthing/releases/download
+
+syncthing_download_directory: /tmp
+syncthing_bin_directory: /opt/syncthing
+syncthing_files_directory: /srv/sync
+syncthing_config_directory: "/home/{{ syncthing_user }}/.config/syncthing"
+
+syncthing_b_nat: "false"
+syncthing_b_relays: "false"
+syncthing_b_start_browser: "false"
+syncthing_b_crash_reporting: "false"
+syncthing_b_global_announcements: "false"
remember that computers suck.