le9i0nx / ansible-syncthing Goto Github PK
View Code? Open in Web Editor NEWOpen Source Continuous File Synchronization
Home Page: https://github.com/syncthing/syncthing
License: GNU General Public License v3.0
Open Source Continuous File Synchronization
Home Page: https://github.com/syncthing/syncthing
License: GNU General Public License v3.0
If you don't add the repository and repository key this playbook doesn't do much.
For example stock ubuntu 14.04 running ansible 2.0.1.0
TASK [syncthing : install] *****************************************************
included: /etc/ansible/roles/syncthing/tasks/install.yml for localhost
TASK [syncthing : deb based distros] *******************************************
included: /etc/ansible/roles/syncthing/tasks/os_deb.yml for localhost
TASK [syncthing : install required packages] ***********************************
failed: [localhost] => (item=[u'syncthing', u'syncthing-inotify', u'python-httplib2']) => {"failed": true, "item": ["syncthing", "syncthing-inotify", "python-httplib2"], "msg": "No package matching 'syncthing' is available"}
to retry, use: --limit @playbook.retry
in group_vars , you define device id
device_moto:
- id: "0000000-0000000-0000000-0000000-0000000-0000000-0000000-0000000"
name: "tapik"
but can you get the id without manually config in devices ?
when the node is a whole new device ( never install syncthing before ) , I don't know how to generate the id .
You need to consider patches
From 86f89230483c14ea75b0767be5582437951460a7 Mon Sep 17 00:00:00 2001
From: Paul MARCHAND <[email protected]>
Date: Mon, 8 May 2017 14:37:06 +0200
Subject: [PATCH 1/8] Corrected Handler
---
tasks/main.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tasks/main.yml b/tasks/main.yml
index 72125c7..9c69a4e 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -12,7 +12,7 @@
- name: start
include: start.yml
-- wait_for: port=8384 delay=3 timeout=5
+- wait_for: port=8384 delay=10 timeout=5
- name: config
include: config.yml
--
2.9.3
From ca4ec97c3feef44d0508c1c1878a83f369f66a27 Mon Sep 17 00:00:00 2001
From: Paul MARCHAND <[email protected]>
Date: Mon, 8 May 2017 14:37:23 +0200
Subject: [PATCH 2/8] Increase delay value
---
tasks/os_other.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tasks/os_other.yml b/tasks/os_other.yml
index 2eaa750..943dcd8 100644
--- a/tasks/os_other.yml
+++ b/tasks/os_other.yml
@@ -44,7 +44,7 @@
- name: cp bin
command: cp -f /root/{{syncthing_http_file}}/syncthing {{syncthing_path}}/syncthing
when: syncthing_releases_install != syncthing_releases
- notify: [ 'Restart syncthing' ]
+ notify: [ 'restart syncthing' ]
- name: check chmod chowen
file:
--
2.9.3
From 5d61421291e4f0ec838dbde6093a6a7e5962a010 Mon Sep 17 00:00:00 2001
From: Paul MARCHAND <[email protected]>
Date: Mon, 8 May 2017 14:37:56 +0200
Subject: [PATCH 3/8] Add Support for arm64/Aarch64
---
defaults/main.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/defaults/main.yml b/defaults/main.yml
index 41a2966..d74c97d 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -55,7 +55,7 @@ syncthing__repositories:
#old
syncthing_path: '/usr/local/bin'
-syncthing_architecture: {"x86_64": "amd64", "x86": "386"}
+syncthing_architecture: {"x86_64": "amd64", "x86": "386", "aarch64": "arm64"}
syncthing_system: {"Linux":"linux"}
syncthing_http_file: 'syncthing-{{ syncthing_system[ansible_system]}}-{{ syncthing_architecture[ansible_architecture] }}-v{{syncthing_releases}}'
# end old
--
2.9.3
From 4c4a69f46a01a53d9c19a9bdf4191e594619938c Mon Sep 17 00:00:00 2001
From: Paul MARCHAND <[email protected]>
Date: Mon, 8 May 2017 14:50:02 +0200
Subject: [PATCH 4/8] Corrected typo for folders
---
defaults/main.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/defaults/main.yml b/defaults/main.yml
index d74c97d..85e4076 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -9,7 +9,7 @@ role_syncthing_api: '127.0.0.1:8384'
# .. envvar:: role_syncthing_data
#
role_syncthing_data:
- forders:
+ folders:
- inventory_hosts: '{{ groups.syncthing }}'
path: '/root/Sync'
id: 'default'
--
2.9.3
From 2d5ae48aa9c6692ca487b3e1755c8450cceea368 Mon Sep 17 00:00:00 2001
From: Paul MARCHAND <[email protected]>
Date: Mon, 8 May 2017 14:50:16 +0200
Subject: [PATCH 5/8] Increase delay value
---
tasks/main.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tasks/main.yml b/tasks/main.yml
index 9c69a4e..e064b91 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -12,7 +12,7 @@
- name: start
include: start.yml
-- wait_for: port=8384 delay=10 timeout=5
+- wait_for: port=8384 delay=10 timeout=60
- name: config
include: config.yml
--
2.9.3
From ea5911f60df1f5a41d64fe730941f5ff5fd7a5cf Mon Sep 17 00:00:00 2001
From: Paul MARCHAND <[email protected]>
Date: Mon, 8 May 2017 18:33:43 +0200
Subject: [PATCH 6/8] Change interface
---
tasks/config.yml | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/tasks/config.yml b/tasks/config.yml
index bf518c5..670a690 100644
--- a/tasks/config.yml
+++ b/tasks/config.yml
@@ -11,6 +11,21 @@
set_fact:
syncthing_apikey: "{{ syncthing_apikey_raw.stdout }}"
+- name: Set interface
+ replace:
+ path: ~/.config/syncthing/config.xml
+ regexp: '(.*<address).*:8384.(\/address)'
+ replace: '\1>{{role_syncthing_api}}<\2'
+ become: yes
+ become_user: "{{ role_syncthing_user }}"
+ notify:
+ - restart syncthing
+
+- name: Restart syncthing
+ meta: flush_handlers
+
+- wait_for: host={{ role_syncthing_api.split(':')[0] }} port=8384 delay=10 timeout=60
+
- name: get system config
uri:
url: "http://{{role_syncthing_api}}/rest/system/config"
--
2.9.3
From 2b19ed70a0b04e61d16fb36ef5cce6feced72634 Mon Sep 17 00:00:00 2001
From: Paul MARCHAND <[email protected]>
Date: Tue, 9 May 2017 10:43:26 +0200
Subject: [PATCH 7/8] Support for systemd user level
---
defaults/main.yml | 2 ++
handlers/main.yml | 12 ++++++-
tasks/start.yml | 44 +++++++++++++++++++----
templates/etc/systemd/system/syncthing.service.j2 | 17 +++++++++
4 files changed, 67 insertions(+), 8 deletions(-)
create mode 100644 templates/etc/systemd/system/syncthing.service.j2
diff --git a/defaults/main.yml b/defaults/main.yml
index 41a2966..4256f37 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -2,6 +2,8 @@
# from which the user starts service
role_syncthing_user: 'root'
+role_syncthing_group: "{{ role_syncthing_user }}"
+role_syncthing_systemd_user_instance: True
# Address Web Interface (for use with api)
role_syncthing_api: '127.0.0.1:8384'
diff --git a/handlers/main.yml b/handlers/main.yml
index a191b7b..7fe4a4e 100644
--- a/handlers/main.yml
+++ b/handlers/main.yml
@@ -4,7 +4,17 @@
shell: sh -c 'echo 204800 > /proc/sys/fs/inotify/max_user_watches'
- name: restart syncthing
- shell: systemctl restart syncthing@{{ role_syncthing_user }}.service
+ systemd:
+ name: syncthing
+ state: restarted
+
+- name: restart user syncthing
+ systemd:
+ name: syncthing
+ state: restarted
+ user: yes
+ become: yes
+ become_user: "{{ role_syncthing_user }}"
- name: reload systemd
shell: systemctl daemon-reload
diff --git a/tasks/start.yml b/tasks/start.yml
index 21e52a5..f53812f 100644
--- a/tasks/start.yml
+++ b/tasks/start.yml
@@ -1,9 +1,8 @@
---
-
- name: install the systemd unit file
template:
- src: 'etc/systemd/system/[email protected]'
- dest: '/etc/systemd/system/[email protected]'
+ src: 'etc/systemd/system/syncthing.service.j2'
+ dest: '/etc/systemd/system/syncthing.service'
owner: 'root'
group: 'root'
mode: '0644'
@@ -12,17 +11,48 @@
when: ((ansible_service_mgr|d()) and
(ansible_service_mgr in [ "systemd" ]) and
(ansible_pkg_mgr != "apt") and
- (ansible_distribution != "Debian" ))
+ (ansible_distribution != "Debian" ) and
+ not role_syncthing_systemd_user_instance )
- name: register autostart service systemd
- service:
- name: 'syncthing@{{ role_syncthing_user }}'
+ systemd:
+ name: 'syncthing'
enabled: 'yes'
state: 'started'
notify:
- restart syncthing
when: ((ansible_service_mgr|d()) and
- (ansible_service_mgr in [ "systemd" ]))
+ (ansible_service_mgr in [ "systemd" ]) and
+ not role_syncthing_systemd_user_instance )
+
+- name: install the systemd unit user file
+ template:
+ src: 'etc/systemd/system/syncthing.service.j2'
+ dest: '/home/{{ role_syncthing_user }}/.config/systemd/user/syncthing.service'
+ owner: "{{ role_syncthing_user }}"
+ group: "{{ role_syncthing_group }}"
+ mode: '0644'
+ notify:
+ - reload systemd
+ when: ((ansible_service_mgr|d()) and
+ (ansible_service_mgr in [ "systemd" ]) and
+ (ansible_pkg_mgr != "apt") and
+ (ansible_distribution != "Debian" ) and
+ role_syncthing_systemd_user_instance )
+
+- name: register autostart user service systemd
+ systemd:
+ name: 'syncthing'
+ enabled: 'yes'
+ state: 'started'
+ user: yes
+ notify:
+ - restart user syncthing
+ become: yes
+ become_user: "{{ role_syncthing_user }}"
+ when: ((ansible_service_mgr|d()) and
+ (ansible_service_mgr in [ "systemd" ]) and
+ role_syncthing_systemd_user_instance )
- name: copy the init.d file
template:
diff --git a/templates/etc/systemd/system/syncthing.service.j2 b/templates/etc/systemd/system/syncthing.service.j2
new file mode 100644
index 0000000..18196c3
--- /dev/null
+++ b/templates/etc/systemd/system/syncthing.service.j2
@@ -0,0 +1,17 @@
+#{{ ansible_managed }}
+[Unit]
+Description=Syncthing - Open Source Continuous File Synchronization for {% role_syncthing_systemd_user_instance %}%I{% else %}{{ role_syncthing_user }}{%endif %}
+Documentation=http://docs.syncthing.net/
+After=network.target
+
+[Service]
+Environment=STNORESTART=yes
+User={% role_syncthing_systemd_user_instance %}%i{% else %}{{ role_syncthing_user }}{%endif %}
+ExecStart={{syncthing_path}}/syncthing -no-browser -logflags=0
+Restart=on-failure
+SuccessExitStatus=2 3 4
+RestartForceExitStatus=3 4
+
+[Install]
+WantedBy=multi-user.target
+
--
2.9.3
From 0edcd4aa037423ba024447c56b86f92289b7e2d4 Mon Sep 17 00:00:00 2001
From: Paul MARCHAND <[email protected]>
Date: Tue, 9 May 2017 11:45:22 +0200
Subject: [PATCH 8/8] Add Fedora Support
---
handlers/main.yml | 2 ++
tasks/config.yml | 1 +
tasks/install.yml | 9 +++++++--
tasks/os_dnf.yml | 20 ++++++++++++++++++++
templates/etc/systemd/system/syncthing.service.j2 | 5 +++--
templates/etc/systemd/system/[email protected] | 17 -----------------
6 files changed, 33 insertions(+), 21 deletions(-)
create mode 100644 tasks/os_dnf.yml
delete mode 100644 templates/etc/systemd/system/[email protected]
diff --git a/handlers/main.yml b/handlers/main.yml
index 7fe4a4e..d0d4005 100644
--- a/handlers/main.yml
+++ b/handlers/main.yml
@@ -7,6 +7,7 @@
systemd:
name: syncthing
state: restarted
+ when: not role_syncthing_systemd_user_instance
- name: restart user syncthing
systemd:
@@ -15,6 +16,7 @@
user: yes
become: yes
become_user: "{{ role_syncthing_user }}"
+ when: role_syncthing_systemd_user_instance
- name: reload systemd
shell: systemctl daemon-reload
diff --git a/tasks/config.yml b/tasks/config.yml
index 670a690..b3f1563 100644
--- a/tasks/config.yml
+++ b/tasks/config.yml
@@ -20,6 +20,7 @@
become_user: "{{ role_syncthing_user }}"
notify:
- restart syncthing
+ - restart user syncthing
- name: Restart syncthing
meta: flush_handlers
diff --git a/tasks/install.yml b/tasks/install.yml
index 3c93c29..0e530b9 100644
--- a/tasks/install.yml
+++ b/tasks/install.yml
@@ -4,16 +4,21 @@
include: os_deb.yml
when: ansible_pkg_mgr == 'apt'
-- name: yum based distros
+- name: yum based distros(CentOS)
include: os_yum.yml
when: ansible_pkg_mgr == 'yum'
+- name: dnf based distros(Fedora)
+ include: os_dnf.yml
+ when: ansible_pkg_mgr == 'dnf'
+
- name: pacman based distros
include: os_pacman.yml
when: ansible_pkg_mgr == 'pacman'
- name: other based distros
include: os_other.yml
- when: (ansible_os_family != 'Debian' and ansible_os_family != 'Archlinux')
+ when: (ansible_os_family != 'Debian' and ansible_os_family != 'Archlinux') or
+ (ansible_distribution == 'Fedora' and ansible_architecture != 'aarch64' )
## vim: foldmethod=marker:tabstop=2:shiftwidth=2:softtabstop=2
diff --git a/tasks/os_dnf.yml b/tasks/os_dnf.yml
new file mode 100644
index 0000000..85e5248
--- /dev/null
+++ b/tasks/os_dnf.yml
@@ -0,0 +1,20 @@
+---
+- name: install required packages
+ dnf:
+ name: '{{ item }}'
+ state: 'present'
+ with_flattened:
+ - 'wget'
+ - 'python-httplib2'
+ when: ansible_architecture == 'aarch64'
+
+- name: install required packages
+ dnf:
+ name: '{{ item }}'
+ state: 'present'
+ with_flattened:
+ - 'wget'
+ - 'syncthing'
+ - 'syncthing-inotify'
+ - 'python-httplib2'
+ when: ansible_architecture != 'aarch64'
diff --git a/templates/etc/systemd/system/syncthing.service.j2 b/templates/etc/systemd/system/syncthing.service.j2
index 18196c3..4047451 100644
--- a/templates/etc/systemd/system/syncthing.service.j2
+++ b/templates/etc/systemd/system/syncthing.service.j2
@@ -1,12 +1,13 @@
#{{ ansible_managed }}
[Unit]
-Description=Syncthing - Open Source Continuous File Synchronization for {% role_syncthing_systemd_user_instance %}%I{% else %}{{ role_syncthing_user }}{%endif %}
+Description=Syncthing - Open Source Continuous File Synchronization for {% if role_syncthing_systemd_user_instance %}%I{% else %}{{ role_syncthing_user }}{%endif %}
Documentation=http://docs.syncthing.net/
After=network.target
[Service]
Environment=STNORESTART=yes
-User={% role_syncthing_systemd_user_instance %}%i{% else %}{{ role_syncthing_user }}{%endif %}
+User={% if role_syncthing_systemd_user_instance %}%i{% else %}{{ role_syncthing_user }}{% endif %}
+
ExecStart={{syncthing_path}}/syncthing -no-browser -logflags=0
Restart=on-failure
SuccessExitStatus=2 3 4
diff --git a/templates/etc/systemd/system/[email protected] b/templates/etc/systemd/system/[email protected]
deleted file mode 100644
index 51f8a5d..0000000
--- a/templates/etc/systemd/system/[email protected]
+++ /dev/null
@@ -1,17 +0,0 @@
-#{{ ansible_managed }}
-[Unit]
-Description=Syncthing - Open Source Continuous File Synchronization for %I
-Documentation=http://docs.syncthing.net/
-After=network.target
-
-[Service]
-Environment=STNORESTART=yes
-User=%i
-ExecStart={{syncthing_path}}/syncthing -no-browser -logflags=0
-Restart=on-failure
-SuccessExitStatus=2 3 4
-RestartForceExitStatus=3 4
-
-[Install]
-WantedBy=multi-user.target
-
--
2.9.3
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.