forked from GovStackWorkingGroup/IM_Demo_InstallingScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ereg_coresystem.yml
411 lines (356 loc) · 11.6 KB
/
ereg_coresystem.yml
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
---
- name: Include a play after another play
import_playbook: haproxy-certs.yml
- name: Core system setup for eregistrations v4
hosts: all
vars_files: vars_with_secret.yml
vars:
words: "{{ inventory_hostname.split('.') }}"
domain_name: "{{ words[0]+'.ext.'+'.'.join(words[1:]) }}"
tasks:
- name: Purge unneeded packages
apt:
pkg:
- dovecot
- sw-nginx
- sw-engine
- sw-cp-server
- sw-collectd
- apache2*
- mysql-common
- postfix*
- bind9*
# - plesk*
state: absent
install_recommends: no
become: true
# See https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
- name: Add mongodb-org apt signing key
ansible.builtin.apt_key:
url: https://www.mongodb.org/static/pgp/server-5.0.asc
state: present
become: true
- name: Add mongodb-org repository into sources list
ansible.builtin.apt_repository:
repo: deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse
state: present
become: true
- name: Install mongodb-org
apt:
pkg:
- mongodb-org
install_recommends: no
become: true
- name: In /etc/mongod.conf change 'bindIp 127.0.0.1' to 0.0.0.0
lineinfile:
path: /etc/mongod.conf
regexp: '^ bindIp: 127.0.0.1'
line: ' bindIp: 0.0.0.0'
become: true
- name: Start mongodb, also on reboot
ansible.builtin.service:
name: mongod
state: started
enabled: yes
become: true
# See https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-elasticsearch-on-ubuntu-20-04
- name: Add elasticsearch apt signing key
ansible.builtin.apt_key:
url: https://artifacts.elastic.co/GPG-KEY-elasticsearch
state: present
become: true
- name: Add elasticsearch repository into sources list
ansible.builtin.apt_repository:
repo: deb https://artifacts.elastic.co/packages/7.x/apt stable main
state: present
become: true
- name: Install elasticsearch, required for graylog
apt:
pkg:
- elasticsearch
install_recommends: no
become: true
- name: In /etc/elasticsearch/elasticsearch.yml change network.host to 0.0.0.0
lineinfile:
path: /etc/elasticsearch/elasticsearch.yml
regexp: '^#network.host: 192.168.0.1'
line: 'network.host: 0.0.0.0'
become: true
- name: In /etc/elasticsearch/elasticsearch.yml change cluster.initial_master_nodes to node-1
lineinfile:
path: /etc/elasticsearch/elasticsearch.yml
regexp: '^#cluster.initial_master_nodes: \[\"node-1\", \"node-2\"\]'
line: 'cluster.initial_master_nodes: ["node-1"]'
become: true
- name: In /etc/elasticsearch/elasticsearch.yml change node.name to node-1
lineinfile:
path: /etc/elasticsearch/elasticsearch.yml
regexp: '^#node.name: node-1'
line: 'node.name: node-1'
become: true
- name: Start elasticsearch, also on reboot
ansible.builtin.service:
name: elasticsearch
state: started
enabled: yes
become: true
# See https://docs.docker.com/engine/install/ubuntu/
- name: Add docker apt signing key
ansible.builtin.apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
become: true
- name: Add docker repository into sources list
ansible.builtin.apt_repository:
repo: deb [ arch=amd64 ] https://download.docker.com/linux/ubuntu focal stable
state: present
become: true
- name: Install docker-ce
apt:
pkg:
- docker-ce
- docker-ce-cli
- containerd.io
install_recommends: no
become: true
# See https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-zabbix-to-securely-monitor-remote-servers-on-ubuntu-20-04
- name: Install zabbix .deb package
apt:
deb: https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+focal_all.deb
install_recommends: no
become: true
- name: Install zabbix-agent2
apt:
pkg: zabbix-agent2
update_cache: yes
install_recommends: no
become: true
# See https://haproxy.debian.net/#?distribution=Ubuntu&release=focal&version=2.4
- name: Install software-properties-common for haproxy
apt:
pkg: software-properties-common
install_recommends: no
become: true
- name: Add haproxy repository into sources list
ansible.builtin.apt_repository:
repo: ppa:vbernat/haproxy-2.4
state: present
become: true
- name: Install haproxy
apt:
pkg: haproxy=2.4.*
update_cache: yes
install_recommends: no
become: true
- name: Install additional packages
apt:
pkg:
- auditd
- screen
- git
- qemu-guest-agent
- pbzip2
- python3-venv
- python3-pip
- vim-nox
- htop
- ncftp
- certbot
- ufw
- haproxyctl
- apt-transport-https
- ca-certificates
- curl
- default-jdk
- aptitude
- postgresql
- mongodb-org
- redis-server
- socat
- acl # for postgres/ansible
install_recommends: no
become: true
- name: In /etc/redis/redis.conf change 'bind 127.0.0.1 ::1' -> 'bind 0.0.0.0'
lineinfile:
path: /etc/redis/redis.conf
regexp: '^bind 127.0.0.1 ::1'
line: 'bind 0.0.0.0'
become: true
- name: Start redis, also on reboot
ansible.builtin.service:
name: redis
state: started
enabled: yes
become: true
# Required for Ansible docker support, see https://docs.ansible.com/ansible/latest/collections/community/docker/docsite/scenario_guide.html#ansible-collections-community-docker-docsite-scenario-guide
- name: Install Ansible Docker support for Python
pip:
name: docker,docker-compose
become: true
- name: Allow docker to connect to postgres
blockinfile:
create: yes
dest: /etc/postgresql/12/main/postgresql.conf
block: |
listen_addresses = '*'
become: true
- name: Allow all authenticated users to connect to postgres (for keycloak inside docker)
postgresql_pg_hba:
dest: /etc/postgresql/12/main/pg_hba.conf
contype: host
users: all
source: 0.0.0.0/0
databases: all
method: md5
create: true
become: true
- name: Restart postgres
service:
name: postgresql
state: restarted
become: true
- name: Install Ansible postgres support for Python
pip:
name: psycopg2-binary
become: true
- name: Reset postgres database user
become: true
become_user: postgres
postgresql_user:
name: postgres
password: "{{ postgres_db_pass }}"
# install eregistrations
- name: Add the ereg user
ansible.builtin.user:
name: ereg
become: true
- name: Creates directory
ansible.builtin.file:
path: /opt/eregistrations
state: directory
mode: '0755'
become: true
- name: Clone eregistrations repo
ansible.builtin.git:
repo: https://bitbucket.org/unctad/eregistrations-starter-conf.git
dest: /opt/eregistrations
single_branch: yes
version: master
become: true
- name: Install specified python requirements
pip:
requirements: /opt/eregistrations/scripts/requirements.txt
become: true
- name: Generate ereg passwords
ansible.builtin.shell: python3 /opt/eregistrations/scripts/deploy.py --auth-service=KEYCLOAK --step-pwd
args:
chdir: /opt/eregistrations/scripts
become: true
- name: Clean ereg auth
ansible.builtin.shell: python3 /opt/eregistrations/scripts/deploy.py --auth-service=KEYCLOAK --step-auth
args:
chdir: /opt/eregistrations/scripts
become: true
# Update /opt/eregistrations/compose/eregistrations/.env for all #changeme entries:
- name: Substitute FORMIO_EMAIL
lineinfile:
path: /opt/eregistrations/compose/eregistrations/.env
regexp: '^FORMIO_EMAIL= #changeme'
line: 'FORMIO_EMAIL={{ formio_email }}'
become: true
- name: Substitute GRAYLOG_ROOT_PASSWORD
lineinfile:
path: /opt/eregistrations/compose/eregistrations/.env
regexp: '^GRAYLOG_ROOT_PASSWORD=e65ec2b4e96ecae33c4c67da69cbd3cbf72c8635ac4fb3292b5980befc851802 #changeme'
line: 'GRAYLOG_ROOT_PASSWORD={{ graylog_root_password }}'
become: true
- name: Substitute MAIL_HOST
lineinfile:
path: /opt/eregistrations/compose/eregistrations/.env
regexp: '^MAIL_HOST=mail.unctad.org #changeme'
line: 'MAIL_HOST={{ smtp_host }}'
become: true
- name: Substitute MAIL_PORT
lineinfile:
path: /opt/eregistrations/compose/eregistrations/.env
regexp: '^MAIL_PORT=mail.unctad.org #changeme'
line: 'MAIL_PORT={{ smtp_port }}'
become: true
- name: Substitute MAIL_USERNAME
lineinfile:
path: /opt/eregistrations/compose/eregistrations/.env
regexp: '^MAIL_USERNAME=none #changeme'
line: 'MAIL_USERNAME={{ smtp_username }}'
become: true
- name: Substitute MAIL_PASSWORD
lineinfile:
path: /opt/eregistrations/compose/eregistrations/.env
regexp: '^MAIL_PASSWORD=none #changeme'
line: 'MAIL_PASSWORD={{ smtp_password }}'
become: true
- name: Substitute MAIL_REPLY_TO
lineinfile:
path: /opt/eregistrations/compose/eregistrations/.env
regexp: '^[email protected] #changeme'
line: 'MAIL_REPLY_TO={{ smtp_replyto }}'
become: true
- name: Substitute MAIL_FROM
lineinfile:
path: /opt/eregistrations/compose/eregistrations/.env
regexp: '^[email protected] #changeme'
line: 'MAIL_FROM={{ smtp_from }}'
become: true
- name: Substitute SYSTEM_CODE
lineinfile:
path: /opt/eregistrations/compose/eregistrations/.env
regexp: '^SYSTEM_CODE=CH #changeme'
line: 'SYSTEM_CODE={{ system_code }}'
become: true
- name: Substitute DEFAULT_LANGUAGE
lineinfile:
path: /opt/eregistrations/compose/eregistrations/.env
regexp: '^DEFAULT_LANGUAGE=en #changeme'
line: 'DEFAULT_LANGUAGE={{ default_language }}'
become: true
- name: Substitute YOUR_DOMAIN_NAME
lineinfile:
path: /opt/eregistrations/compose/eregistrations/.env
regexp: '^YOUR_DOMAIN_NAME=eregistrations.org #changeme'
line: 'YOUR_DOMAIN_NAME={{ domain_name }}'
become: true
- name: Substitute TIME_ZONE
lineinfile:
path: /opt/eregistrations/compose/eregistrations/.env
regexp: '^TIME_ZONE=Europe/Zurich #changeme'
line: 'TIME_ZONE={{ time_zone }}'
become: true
- name: Substitute DOCKER_PASSWORD
lineinfile:
path: /opt/eregistrations/compose/eregistrations/.env
regexp: '^DOCKER_PASSWORD= #askus'
line: 'DOCKER_PASSWORD={{ docker_password }}'
become: true
- name: Substitute PATH_TO_SSL_CERTIFICATE
lineinfile:
path: /opt/eregistrations/compose/eregistrations/.env
regexp: '^PATH_TO_SSL_CERTIFICATE=/etc/letsencrypt/live/YOUR_DOMAIN_NAME/haproxy.crt #changeme'
line: "PATH_TO_SSL_CERTIFICATE={{ ' crt '.join(haproxy_certs) }}"
become: true
- name: Finish ereg install
ansible.builtin.shell: python3 /opt/eregistrations/scripts/deploy.py --auth-service=KEYCLOAK --step-all
args:
chdir: /opt/eregistrations/scripts
become: true
- name: Set permissions
ansible.builtin.file:
path: /opt/eregistrations
state: directory
owner: ereg
group: ereg
mode: '0755'
become: true
# NOTE: can only reboot after keycloak comes up the first time...
# - name: Reboot
# reboot:
# reboot_timeout: 3600
# become: true