main.yml 8.51 KB
Newer Older
1
2
---

3
- name: create ssl cert
4
5
6
7
  include_role:
    name: certificate
  vars:
    domains: ["{{ matrix_domain }}"]
8
  when: 'matrix_domain is defined'
9
10

- name: install packages
11
12
  pacman:
    name:
13
      - coturn
14
15
16
17
18
      - freetype2
      - gcc
      - git
      - jemalloc
      - libffi
19
      - libjpeg-turbo
20
      - libolm
21
22
23
24
25
26
27
28
29
30
31
      - libtiff
      - libwebp
      - libxslt
      - libzip
      - make
      - npm
      - openssl
      - pkgconf
      - postgresql-libs
      - python
      - python2
32
      - redis
33
34
      - tcl
      - tk
35
      - yarn
36
      - zlib
37
38
39
40
41
42
43
44

- name: add synapse group
  group: name=synapse system=yes gid=198

- name: add synapse user
  user: name=synapse system=yes uid=198 group=synapse home=/var/lib/synapse shell=/bin/false createhome=no

- name: create synapse home
45
  file: path={{ item }} state=directory owner=synapse group=synapse mode=0700
46
47
48
  with_items:
    - /var/lib/synapse
    - /var/lib/synapse/media_store
49
50
51
    - /var/lib/synapse/mjolnir-data
    - /var/lib/synapse/pantalaimon-data

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
- name: make virtualenvs
  command: 'python -m venv {{ item }}'
  args:
    creates: '{{ item }}/bin/python'
  become: true
  become_user: synapse
  become_method: sudo
  with_items:
    - /var/lib/synapse/venv
    - /var/lib/synapse/venv-pantalaimon

- name: update virtualenvs
  pip:
    name:
      - pip
      - wheel
    state: latest
    extra_args: '--upgrade-strategy=eager'
    virtualenv: '{{ item }}'
  become: yes
  become_user: synapse
  become_method: sudo
  with_items:
    - /var/lib/synapse/venv
    - /var/lib/synapse/venv-pantalaimon

- name: install synapse
  pip:
    name:
      - 'matrix-synapse[postgres,systemd,url_preview,redis]==1.26.0'
    state: latest
    extra_args: '--upgrade-strategy=eager'
    virtualenv: /var/lib/synapse/venv
  become: yes
  become_user: synapse
  become_method: sudo
  notify:
    - restart synapse

- name: install pantalaimon
  pip:
    name:
      - 'pantalaimon==0.9.1'
    state: latest
    extra_args: '--upgrade-strategy=eager'
    virtualenv: /var/lib/synapse/venv-pantalaimon
  become: yes
  become_user: synapse
  become_method: sudo
  notify:
    - restart pantalaimon

104
105
106
107
108
109
110
111
- name: download mjolnir
  git:
    repo: https://github.com/matrix-org/mjolnir
    dest: /var/lib/synapse/mjolnir
    version: v0.1.16
  become: yes
  become_user: synapse
  become_method: sudo
112
  register: mjolnir_git
113
114
115
116
117
118
119
120
121
  notify:
    - restart mjolnir

- name: install mjolnir
  community.general.yarn:
    path: /var/lib/synapse/mjolnir
  become: yes
  become_user: synapse
  become_method: sudo
122
  when: mjolnir_git.changed
123
124
125
126
127
128
129
130

- name: build mjolnir
  command: yarn build
  args:
    chdir: /var/lib/synapse/mjolnir
  become: true
  become_user: synapse
  become_method: sudo
131
  when: mjolnir_git.changed
132

133
- name: install mjolnir antispam module
134
135
  pip:
    name:
136
      - /var/lib/synapse/mjolnir/synapse_antispam
137
    state: latest
138
    virtualenv: /var/lib/synapse/venv
139
140
141
  become: yes
  become_user: synapse
  become_method: sudo
142
  when: mjolnir_git.changed
143
144
  notify:
    - restart synapse
145

146
- name: download matrix-appservice-irc
147
  git:
148
    repo: https://github.com/matrix-org/matrix-appservice-irc
149
    dest: /var/lib/synapse/matrix-appservice-irc
150
    version: 0.23.0
151
152
153
  become: yes
  become_user: synapse
  become_method: sudo
154
  register: irc_git
155
156
  notify:
    - restart matrix-appservice-irc
157
158

- name: install matrix-appservice-irc
159
160
  npm:
    path: /var/lib/synapse/matrix-appservice-irc
161
162
163
  become: yes
  become_user: synapse
  become_method: sudo
164
  when: irc_git.changed
165

166
167
168
169
170
- name: install pg_hba.conf
  copy: src=pg_hba.conf dest=/var/lib/postgres/data/pg_hba.conf owner=postgres group=postgres mode=0600
  notify:
    - restart postgres

171
172
173
174
175
176
177
- name: add synapse postgres db
  postgresql_db: db=synapse
  become: yes
  become_user: postgres
  become_method: su

- name: add synapse postgres user
178
179
180
181
182
183
184
  postgresql_user: db=synapse user=synapse password={{ vault_postgres_users.synapse }}
  become: yes
  become_user: postgres
  become_method: su

- name: add irc postgres db
  postgresql_db: db=irc
185
186
187
188
  become: yes
  become_user: postgres
  become_method: su

189
- name: create synapse config dir
190
191
192
193
  file: path={{ item }} state=directory owner=root group=synapse mode=0750
  with_items:
    - /etc/synapse
    - /etc/synapse/mjolnir
194
195
196

- name: install homeserver config
  template: src=homeserver.yaml.j2 dest=/etc/synapse/homeserver.yaml owner=root group=synapse mode=0640
197
198
  notify:
    - restart synapse
199

200
201
202
203
204
- name: install static config
  copy: src={{ item }} dest=/etc/synapse/{{ item }} owner=root group=root mode=0644
  with_items:
    - log_config.yaml
    - worker-appservice.yaml
205
    - worker-federation_reader.yaml
206
    - worker-federation_sender.yaml
207
    - worker-media_repository.yaml
208
209
  notify:
    - restart synapse
210

211
212
213
214
215
216
217
218
219
220
- name: install pantalaimon config
  template: src=pantalaimon.conf.j2 dest=/etc/synapse/pantalaimon.conf owner=root group=synapse mode=0644
  notify:
    - restart pantalaimon

- name: install mjolnir config
  template: src=mjolnir.yaml.j2 dest=/etc/synapse/mjolnir/production.yaml owner=root group=synapse mode=0640
  notify:
    - restart mjolnir

221
222
- name: install irc-bridge config
  template: src=irc-bridge.yaml.j2 dest=/etc/synapse/irc-bridge.yaml owner=root group=synapse mode=0640
223
224
  notify:
    - restart matrix-appservice-irc
225
226
227

- name: install irc-bridge registration
  template: src=appservice-registration-irc.yaml.j2 dest=/etc/synapse/appservice-registration-irc.yaml owner=root group=synapse mode=0640
228
229
  notify:
    - restart synapse
230

231
232
- name: install signing key
  copy:
233
    content: '{{ vault_matrix_secrets.signing_key }}'
234
235
236
237
238
    dest: /etc/synapse/{{ matrix_server_name }}.signing.key
    owner: root
    group: synapse
    mode: 0640

239
240
- name: install ircpass key
  copy:
241
    content: '{{ vault_matrix_secrets.ircpass_key }}'
242
243
244
245
    dest: /etc/synapse/{{ matrix_server_name }}.ircpass.key
    owner: root
    group: synapse
    mode: 0640
246
247
248
249
250
251
252
253

- name: make nginx log dir
  file: path=/var/log/nginx/{{ matrix_domain }} state=directory owner=root group=root mode=0755

- name: set up nginx
  template: src=nginx.d.conf.j2 dest=/etc/nginx/nginx.d/matrix.conf owner=root group=root mode=0644
  notify:
    - reload nginx
254
  when: 'matrix_domain is defined'
255
  tags: ['nginx']
256

257
- name: install turnserver.conf
258
  template: src=turnserver.conf.j2 dest=/etc/turnserver/turnserver.conf owner=turnserver group=turnserver mode=0600
259
260
261
262
263
264
  notify:
    - restart turnserver

- name: install turnserver cert renewal hook
  copy: src=letsencrypt.hook.d dest=/etc/letsencrypt/hook.d/turnserver owner=root group=root mode=0755

265
- name: install synapse units
266
267
268
  copy: src={{ item }} dest=/etc/systemd/system/{{ item }} owner=root group=root mode=0644
  with_items:
    - synapse.service
269
270
271
272
    - synapse-worker@.service
  notify:
    - restart synapse

273
274
275
276
277
278
279
280
281
282
283
284
285
286
- name: install pantalaimon units
  copy: src={{ item }} dest=/etc/systemd/system/{{ item }} owner=root group=root mode=0644
  with_items:
    - pantalaimon.service
  notify:
    - restart pantalaimon

- name: install mjolnir units
  copy: src={{ item }} dest=/etc/systemd/system/{{ item }} owner=root group=root mode=0644
  with_items:
    - mjolnir.service
  notify:
    - restart mjolnir

287
288
289
- name: install matrix-appservice-irc units
  copy: src={{ item }} dest=/etc/systemd/system/{{ item }} owner=root group=root mode=0644
  with_items:
290
    - matrix-appservice-irc.service
291
292
293
  notify:
    - restart matrix-appservice-irc

294
295
296
297
298
299
300
- name: install turnserver units
  copy: src={{ item }} dest=/etc/systemd/system/{{ item }} owner=root group=root mode=0644
  with_items:
    - turnserver.service
  notify:
    - restart turnserver

301
302
303
304
305
- name: enable synapse units
  service: name={{ item }} enabled=yes
  with_items:
    - synapse.service
    - synapse-worker@appservice.service
306
    - synapse-worker@federation_reader.service
307
    - synapse-worker@federation_sender.service
308
    - synapse-worker@media_repository.service
309
  notify:
310
    - restart synapse
311

312
313
314
315
316
317
318
319
320
321
- name: enable pantalaimon units
  service: name={{ item }} enabled=yes
  with_items:
    - pantalaimon.service

- name: enable mjolnir units
  service: name={{ item }} enabled=yes
  with_items:
    - mjolnir.service

322
323
324
325
- name: enable matrix-appservice-irc units
  service: name={{ item }} enabled=yes
  with_items:
    - matrix-appservice-irc.service
326

327
328
329
330
331
- name: enable turnserver units
  service: name={{ item }} enabled=yes
  with_items:
    - turnserver.service

332
- name: open firewall holes
333
  ansible.posix.firewalld: port={{ item }} permanent=true state=enabled immediate=yes
334
  with_items:
335
    # synapse's identd
336
    - 113/tcp
337
338
339
340
341
342
    # turnserver
    - 3478-3479/tcp
    - 3478-3479/udp
    - 5349-5350/tcp
    - 5349-5350/udp
    - 33000-33999/udp
343
344
  when: configure_firewall
  tags:
345
    - firewall