main.yml 7.61 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
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
    - /var/lib/synapse/mjolnir-data
    - /var/lib/synapse/pantalaimon-data

- 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
  notify:
    - restart mjolnir

- name: install mjolnir
  community.general.yarn:
    path: /var/lib/synapse/mjolnir
  become: yes
  become_user: synapse
  become_method: sudo

- name: build mjolnir
  command: yarn build
  args:
    chdir: /var/lib/synapse/mjolnir
  become: true
  become_user: synapse
  become_method: sudo
77

78
79
80
81
82
83
84
85
- name: make virtualenv
  command: python -m venv /var/lib/synapse/venv
  args:
    creates: /var/lib/synapse/venv/bin/python
  become: true
  become_user: synapse
  become_method: sudo

86
- name: install python packages
87
88
  pip:
    name:
89
90
91
      - 'matrix-synapse[postgres,systemd,url_preview,redis]==1.26.0'
      - 'pantalaimon==0.9.1'
      - /var/lib/synapse/mjolnir/synapse_antispam
92
      - pip
93
    state: latest
94
95
    extra_args: '-U --upgrade-strategy=eager'
    virtualenv: /var/lib/synapse/venv
96
97
98
  become: yes
  become_user: synapse
  become_method: sudo
99
100
  notify:
    - restart synapse
101
    - restart pantalaimon
102

103
- name: download matrix-appservice-irc
104
  git:
105
    repo: https://github.com/matrix-org/matrix-appservice-irc
106
    dest: /var/lib/synapse/matrix-appservice-irc
107
    version: 0.23.0
108
109
110
  become: yes
  become_user: synapse
  become_method: sudo
111
112
  notify:
    - restart matrix-appservice-irc
113
114

- name: install matrix-appservice-irc
115
116
  npm:
    path: /var/lib/synapse/matrix-appservice-irc
117
118
119
120
  become: yes
  become_user: synapse
  become_method: sudo

121
122
123
124
125
- 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

126
127
128
129
130
131
132
- name: add synapse postgres db
  postgresql_db: db=synapse
  become: yes
  become_user: postgres
  become_method: su

- name: add synapse postgres user
133
134
135
136
137
138
139
  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
140
141
142
143
  become: yes
  become_user: postgres
  become_method: su

144
- name: create synapse config dir
145
146
147
148
  file: path={{ item }} state=directory owner=root group=synapse mode=0750
  with_items:
    - /etc/synapse
    - /etc/synapse/mjolnir
149
150
151

- name: install homeserver config
  template: src=homeserver.yaml.j2 dest=/etc/synapse/homeserver.yaml owner=root group=synapse mode=0640
152
153
  notify:
    - restart synapse
154

155
156
157
158
159
- 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
160
    - worker-federation_reader.yaml
161
    - worker-federation_sender.yaml
162
    - worker-media_repository.yaml
163
164
  notify:
    - restart synapse
165

166
167
168
169
170
171
172
173
174
175
- 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

176
177
- name: install irc-bridge config
  template: src=irc-bridge.yaml.j2 dest=/etc/synapse/irc-bridge.yaml owner=root group=synapse mode=0640
178
179
  notify:
    - restart matrix-appservice-irc
180
181
182

- 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
183
184
  notify:
    - restart synapse
185

186
187
- name: install signing key
  copy:
188
    content: '{{ vault_matrix_secrets.signing_key }}'
189
190
191
192
193
    dest: /etc/synapse/{{ matrix_server_name }}.signing.key
    owner: root
    group: synapse
    mode: 0640

194
195
- name: install ircpass key
  copy:
196
    content: '{{ vault_matrix_secrets.ircpass_key }}'
197
198
199
200
    dest: /etc/synapse/{{ matrix_server_name }}.ircpass.key
    owner: root
    group: synapse
    mode: 0640
201
202
203
204
205
206
207
208

- 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
209
  when: 'matrix_domain is defined'
210
  tags: ['nginx']
211

212
- name: install turnserver.conf
213
  template: src=turnserver.conf.j2 dest=/etc/turnserver/turnserver.conf owner=turnserver group=turnserver mode=0600
214
215
216
217
218
219
  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

220
- name: install synapse units
221
222
223
  copy: src={{ item }} dest=/etc/systemd/system/{{ item }} owner=root group=root mode=0644
  with_items:
    - synapse.service
224
225
226
227
    - synapse-worker@.service
  notify:
    - restart synapse

228
229
230
231
232
233
234
235
236
237
238
239
240
241
- 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

242
243
244
- name: install matrix-appservice-irc units
  copy: src={{ item }} dest=/etc/systemd/system/{{ item }} owner=root group=root mode=0644
  with_items:
245
    - matrix-appservice-irc.service
246
247
248
  notify:
    - restart matrix-appservice-irc

249
250
251
252
253
254
255
- 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

256
257
258
259
260
- name: enable synapse units
  service: name={{ item }} enabled=yes
  with_items:
    - synapse.service
    - synapse-worker@appservice.service
261
    - synapse-worker@federation_reader.service
262
    - synapse-worker@federation_sender.service
263
    - synapse-worker@media_repository.service
264
  notify:
265
    - restart synapse
266

267
268
269
270
271
272
273
274
275
276
- 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

277
278
279
280
- name: enable matrix-appservice-irc units
  service: name={{ item }} enabled=yes
  with_items:
    - matrix-appservice-irc.service
281

282
283
284
285
286
- name: enable turnserver units
  service: name={{ item }} enabled=yes
  with_items:
    - turnserver.service

287
- name: open firewall holes
288
  ansible.posix.firewalld: port={{ item }} permanent=true state=enabled immediate=yes
289
  with_items:
290
    # synapse's identd
291
    - 113/tcp
292
293
294
295
296
297
    # turnserver
    - 3478-3479/tcp
    - 3478-3479/udp
    - 5349-5350/tcp
    - 5349-5350/udp
    - 33000-33999/udp
298
299
  when: configure_firewall
  tags:
300
    - firewall