aboutsummaryrefslogtreecommitdiffstats
path: root/roles/setup_syncthing/tasks/main.yml
blob: 431f27f0d0d7fa57d82a6fce8729e56e0b9ad3ac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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

remember that computers suck.