-
Notifications
You must be signed in to change notification settings - Fork 0
/
playbook.yml
executable file
·319 lines (284 loc) · 7.57 KB
/
playbook.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
---
- hosts: "app:mongo"
become: yes
tags:
- dependencies
tasks:
- name: Upgrade packages
ansible.builtin.apt:
update_cache: yes
upgrade: 'yes'
- name: Register reboot required file
stat:
path: /var/run/reboot-required
register: reboot_required
- name: Reboot if Required
reboot:
when: reboot_required.stat.exists
- hosts: app
become: yes
tags:
- dependencies
- python
tasks:
- name: Install python deployment dependencies
ansible.builtin.apt:
name:
- jq
- python3-pip
- python3-venv
state: present
- name: Install virtualenv via pip
ansible.builtin.pip:
name: virtualenv
executable: pip3
- name: Install boto requirement
ansible.builtin.pip:
name:
- boto3
- botocore
state: present
- hosts: app
become: yes
tags:
- dependencies
tasks:
- name: Check for built htslib
ansible.builtin.stat:
path: "/usr/local/bin/htslib"
register: hts_stat
- name: Build htslib
ansible.builtin.include_role:
name: htslib
when: not hts_stat.stat.exists
- hosts: mongo
become: yes
tags:
- dependencies
tasks:
- name: Unzip
ansible.builtin.apt:
name:
- unzip
state: present
- name: Download aws cli installer
ansible.builtin.unarchive:
src: "https://awscli.amazonaws.com/awscli-exe-linux-{{ansible_architecture}}.zip"
dest: "/tmp"
remote_src: true
creates: "/tmp/aws"
mode: 0755
- name: Install awscli
command:
cmd: /tmp/aws/install
creates: /usr/local/bin/aws
- hosts: "app:mongo"
tags:
- setup
tasks:
- name: Create base directory mount point
become: yes
ansible.builtin.file:
path: "{{base_dir}}"
state: directory
# Could use ebsnvme-id from https://github.com/amazonlinux/amazon-ec2-utils
# to create symlinks that use the original volume name
- name: Format ebs volume
become: yes
ansible.builtin.filesystem:
dev: /dev/nvme1n1
fstype: ext4
- name: Mount ebs volume
become: yes
ansible.posix.mount:
src: /dev/nvme1n1
path: "{{base_dir}}"
fstype: ext4
state: mounted
- name: Set owner of mount point
become: yes
ansible.builtin.file:
path: "{{base_dir}}"
state: directory
owner: "{{ansible_user_id}}"
group: "{{ansible_user_id}}"
- hosts: app
become: no
tags:
- instance
vars:
mongo_host: "{{ groups['mongo'] | first }}"
mongo_ip: "{{ hostvars[mongo_host]['private_ip'] }}"
bravo_ref: "main"
tasks:
- name: Create API instance dir
ansible.builtin.file:
path: "{{inst_dir}}/api"
state: directory
owner: ubuntu
group: ubuntu
- name: Build S3 enabled pysam in API venv
ansible.builtin.pip:
name:
- pysam
virtualenv: "{{inst_dir}}/api/venv"
state: present
extra_args: "--no-binary pysam"
environment:
HTSLIB_CONFIGURE_OPTIONS: "--enable-libcurl --enable-s3"
- name: Install Bravo API and dependencies into API venv
ansible.builtin.pip:
name:
- "git+https://github.com/statgen/bravo_api.git@{{bravo_ref}}"
- gunicorn
- gevent
virtualenv: "{{inst_dir}}/api/venv"
state: present
extra_args: "--upgrade"
- name: Create API config
ansible.builtin.template:
mode: 0775
dest: "{{inst_dir}}/api/config.py"
src: templates/config_api.py.j2
- hosts: app
become: yes
tags:
- instance
- systemd
# From https://www.jeffgeerling.com/blog/2017/quick-way-check-if-youre-aws-ansible-playbook
pre_tasks:
- name: Check if inside AWS.
uri:
url: http://169.254.169.254/latest/meta-data
timeout: 2
register: aws_uri_check
failed_when: False
- set_fact:
is_aws_environment: "{{ aws_uri_check.status == 200 }}"
tasks:
- name: Script for HTSLIB S3 credentials
ansible.builtin.template:
mode: 0755
dest: /usr/local/sbin/hts_credentials.sh
src: templates/hts_credentials.sh.j2
when: is_aws_environment
- name: Systemd service for HTSLIB S3 credentials
ansible.builtin.template:
mode: 0755
dest: /etc/systemd/system/hts-credentials.service
src: templates/hts-credentials.service.j2
when: is_aws_environment
- name: Start credentials service
ansible.builtin.systemd:
daemon_reload: yes
name: hts-credentials.service
enabled: yes
state: restarted
when: is_aws_environment
- name: Systemd service for API
ansible.builtin.template:
mode: 0755
dest: /etc/systemd/system/bravo-api.service
src: templates/bravo-api.service.j2
- name: Reload systemd daemons
ansible.builtin.systemd:
name: bravo-api.service
state: restarted
- hosts: mongo
become: yes
tags:
- database
- dependencies
roles:
- role: community.mongodb.mongodb_repository
vars:
mongodb_version: "4.4"
- role: community.mongodb.mongodb_install
- hosts: mongo
become: yes
tags:
- database
- dependencies
tasks:
- name: Create mongo db directory
ansible.builtin.file:
path: "{{base_dir}}/mongodata"
state: directory
group: mongodb
owner: mongodb
- name: Change mongo db data directory config
ansible.builtin.lineinfile:
path: /etc/mongod.conf
search_string: " dbPath: /var/lib/mongodb"
line: " dbPath: {{base_dir}}/mongodata"
state: present
- name: Change mongo db ip binding
ansible.builtin.lineinfile:
path: /etc/mongod.conf
search_string: " bindIp: 127.0.0.1"
line: " bindIp: 0.0.0.0"
state: present
- hosts: mongo
become: yes
tags:
- database
- dependencies
tasks:
- name: Restart mongod service
ansible.builtin.systemd:
name: mongod.service
state: restarted
enabled: true
- hosts: app
tags:
- data
tasks:
- name: Download runtime data and load basis data into mongo
ansible.builtin.include_role:
name: data_loading
when: load_data
- name: Create runtime reference directory
ansible.builtin.file:
path: "{{base_dir}}/data/runtime/reference"
state: "directory"
- name: Download runtime reference fasta from S3
amazon.aws.s3_object:
bucket: "{{data_bucket}}"
object: "runtime/reference/{{item}}"
mode: "get"
overwrite: "latest"
dest: "{{base_dir}}/data/runtime/reference/{{item}}"
loop:
- "hs38DH.fa"
- "hs38DH.fa.fai"
when: data_bucket | length > 0
- hosts: mongo
tags:
- data
tasks:
- name: Create import script
ansible.builtin.template:
mode: 0775
dest: "/tmp/eqtl_import.sh"
src: templates/eqtl_import.sh.j2
- name: Import eqtl data
block:
- name: Run eqtl import script
command: /tmp/eqtl_import.sh
rescue:
- name: Report eqtl import failure
ansible.builtin.debug:
msg: "Eqtl import did not complete successfully"
- hosts: app
become: yes
gather_facts: no
tags:
- systemd
- start
tasks:
- name: Start API service
ansible.builtin.systemd:
daemon_reload: yes
name: bravo-api.service
enabled: yes
state: started