main.yml 8.4 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
      - libtiff
      - libwebp
      - libxslt
      - libzip
      - make
      - npm
      - openssl
      - pkgconf
      - postgresql-libs
      - python
31
      - redis
32
33
      - tcl
      - tk
34
      - yarn
35
      - zlib
36
37
38
39
40
41
42
43

- 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
44
  file: path={{ item }} state=directory owner=synapse group=synapse mode=0700
45
46
47
  with_items:
    - /var/lib/synapse
    - /var/lib/synapse/media_store
48
49
50
    - /var/lib/synapse/mjolnir-data
    - /var/lib/synapse/pantalaimon-data

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
- 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 }}'
Kristian Klausen's avatar
Kristian Klausen committed
70
  become: true
71
72
73
74
75
76
77
78
79
  become_user: synapse
  become_method: sudo
  with_items:
    - /var/lib/synapse/venv
    - /var/lib/synapse/venv-pantalaimon

- name: install synapse
  pip:
    name:
80
      - 'matrix-synapse[postgres,systemd,url_preview,redis,oidc]==1.42.0'
81
82
83
    state: latest
    extra_args: '--upgrade-strategy=eager'
    virtualenv: /var/lib/synapse/venv
Kristian Klausen's avatar
Kristian Klausen committed
84
  become: true
85
86
  become_user: synapse
  become_method: sudo
87
  register: synapse_pip
88
89
90
91
92
93
  notify:
    - restart synapse

- name: install pantalaimon
  pip:
    name:
94
      - 'pantalaimon==0.10.3'
95
96
97
    state: latest
    extra_args: '--upgrade-strategy=eager'
    virtualenv: /var/lib/synapse/venv-pantalaimon
Kristian Klausen's avatar
Kristian Klausen committed
98
  become: true
99
100
101
102
103
  become_user: synapse
  become_method: sudo
  notify:
    - restart pantalaimon

104
105
106
107
- name: download mjolnir
  git:
    repo: https://github.com/matrix-org/mjolnir
    dest: /var/lib/synapse/mjolnir
108
    version: v0.1.19
Kristian Klausen's avatar
Kristian Klausen committed
109
  become: true
110
111
  become_user: synapse
  become_method: sudo
112
  register: mjolnir_git
113
114
115
116
117
118
  notify:
    - restart mjolnir

- name: install mjolnir
  community.general.yarn:
    path: /var/lib/synapse/mjolnir
Kristian Klausen's avatar
Kristian Klausen committed
119
  become: true
120
121
  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
Kristian Klausen's avatar
Kristian Klausen committed
139
  become: true
140
141
  become_user: synapse
  become_method: sudo
142
  when: synapse_pip.changed or 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.30.0
Kristian Klausen's avatar
Kristian Klausen committed
151
  become: true
152
153
  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
  community.general.npm:
160
    path: /var/lib/synapse/matrix-appservice-irc
161
    ci: true
Kristian Klausen's avatar
Kristian Klausen committed
162
  become: true
163
164
  become_user: synapse
  become_method: sudo
165
  when: irc_git.changed
166

167
168
169
170
171
- 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

172
173
- name: add synapse postgres db
  postgresql_db: db=synapse
Kristian Klausen's avatar
Kristian Klausen committed
174
  become: true
175
176
177
178
  become_user: postgres
  become_method: su

- name: add synapse postgres user
179
  postgresql_user: db=synapse user=synapse password={{ vault_postgres_users.synapse }}
Kristian Klausen's avatar
Kristian Klausen committed
180
  become: true
181
182
183
184
185
  become_user: postgres
  become_method: su

- name: add irc postgres db
  postgresql_db: db=irc
Kristian Klausen's avatar
Kristian Klausen committed
186
  become: true
187
188
189
  become_user: postgres
  become_method: su

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

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

201
202
203
204
205
- 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
206
    - worker-federation_reader.yaml
207
    - worker-federation_sender.yaml
208
    - worker-media_repository.yaml
209
210
  notify:
    - restart synapse
211

212
213
214
215
216
217
218
219
220
221
- 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

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

- 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
229
230
  notify:
    - restart synapse
231

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

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

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

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

258
- name: install turnserver.conf
259
  template: src=turnserver.conf.j2 dest=/etc/turnserver/turnserver.conf owner=turnserver group=turnserver mode=0600
260
261
262
263
264
265
  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

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

274
275
276
277
278
279
280
281
282
283
284
285
286
287
- 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

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

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

306
307
308
309
310
311
312
313
314
315
- 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

316
317
318
319
- name: enable matrix-appservice-irc units
  service: name={{ item }} enabled=yes
  with_items:
    - matrix-appservice-irc.service
320

321
322
323
324
325
- name: enable turnserver units
  service: name={{ item }} enabled=yes
  with_items:
    - turnserver.service

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