-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup-training-environment.yml
308 lines (275 loc) · 7.37 KB
/
setup-training-environment.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
---
- name: Wait for Kubernetes Nodes
hosts: localhost
gather_facts: False
any_errors_fatal: "true"
roles:
- { role: infra/wait-for-hosts }
- name: Install admin SSH keys
hosts: all
tasks:
- name: Install admin SSH keys
authorized_key:
user: "{{ ansible_user }}"
state: present
key: "{{ lookup('file', '{{ item }}')}}"
with_fileglob: 'pubkeys/*.pub'
- name: Set timezone
hosts: all
become: yes
tasks:
- name: Set timezone
community.general.timezone:
name: Pacific/Auckland
- name: Upgrade systems
become: yes
hosts: all
roles:
- upgrade_system
- name: Set hostnames
hosts: all
become: yes
tasks:
- name: Set hostname
ansible.builtin.hostname:
name: "{{ inventory_hostname }}.flexi.nesi"
- hosts: servers
any_errors_fatal: "true"
vars_files:
- ondemand-config.yml
roles:
- { role: pre-checks/letsencrypt-apache2 }
- { role: pre-checks/letsencrypt-cert }
- { role: kubectl }
- hosts: servicesnode
any_errors_fatal: "true"
vars_files:
- ondemand-config.yml
roles:
- { role: pre-checks/openstack }
- { role: pre-checks/kubernetes }
- { role: cluster-ctl/cli-install }
- { role: capi-cluster/workload }
- { role: capi-cluster/get-nodes }
- { role: openondemand-k8s/kuberenetes }
- name: Setup /etc/hosts
hosts: servers
become: yes
gather_facts: yes
tasks:
- name: Add IP address of all hosts to all hosts
lineinfile:
dest: /etc/hosts
line: '{{ hostvars[item]["ansible_default_ipv4"]["address"] }} {{ hostvars[item]["ansible_hostname"] }} {{ hostvars[item]["ansible_nodename"] }}'
state: present
with_items: "{{ groups['servers'] }}"
- name: setup hosts ood-idp
lineinfile:
dest: /etc/hosts
line: '{{ hostvars["servicesnode"]["ansible_default_ipv4"]["address"] }} ood-idp.flexi.nesi'
state: present
- name: setup hosts ood
lineinfile:
dest: /etc/hosts
line: '{{ hostvars["webnode"]["ansible_default_ipv4"]["address"] }} ood.flexi.nesi'
state: present
- name: Exchange SSH keys between servers
hosts: servers
tasks:
- name: Generate SSH key pair
community.crypto.openssh_keypair:
path: ~/.ssh/id_rsa
size: 4096
type: rsa
- name: Fetch the public key from the node to local
fetch:
src: "~/.ssh/id_rsa.pub"
dest: "tmp/pubkeys/{{ansible_hostname}}-id_rsa.pub"
flat: yes
- name: Copy the key to authorized_keys
authorized_key:
user: "{{ ansible_user }}"
state: present
key: "{{ lookup('file','tmp/pubkeys/{{item}}-id_rsa.pub')}}"
with_items:
- "{{ groups['servers'] }}"
- name: Copy SSH key to servicesnode to act as jumphost
hosts: servicesnode
tasks:
- name: Copy key to servicesnode
copy:
src: "{{ lookup('ansible.builtin.env', 'TF_VAR_key_file', default='~/.ssh/id_flexi') }}"
dest: ~/.ssh/id_flexi
mode: '0600'
- name: Setup LDAP server
become: yes
hosts: servicesnode
vars_files:
- ondemand-config.yml
roles:
- ldap_server
- name: Setup LDAP clients
become: yes
hosts: servers
vars_files:
- ondemand-config.yml
roles:
- ldap_client
- name: Setup k8s LDAP clients
become: yes
hosts: ldap_clients
vars_files:
- ondemand-config.yml
roles:
- ldap_client
- name: Setup NFS server
become: yes
hosts: servicesnode
vars_files:
- ondemand-config.yml
roles:
- nfs_homes_server
- name: Setup NFS clients
become: yes
hosts: servers
vars_files:
- ondemand-config.yml
roles:
- nfs_homes_client
- name: Add users
become: yes
hosts: servicesnode
vars_files:
- ondemand-config.yml
roles:
- ldap_add_users
- name: Setup keycloak
become: yes
hosts: servicesnode
vars_files:
- ondemand-config.yml
roles:
- keycloak
- name: Setup linux host cluster
become: yes
hosts: webnode
roles:
- apptainer
# run ondemand role
- name: Install ondemand
become: yes
hosts: webnode
vars_files:
- ondemand-config.yml
pre_tasks:
- name: Get keycloak client secret
community.general.keycloak_clientsecret_info:
client_id: ondemand.flexi
realm: ondemand
auth_client_id: admin-cli
auth_keycloak_url: "https://{{ oidc_hostname }}"
auth_realm: master
auth_username: admin
auth_password: "{{ keycloak_admin_password }}"
validate_certs: false
register: keycloak_secret
no_log: true
- name: Set keycloak client secret fact for ondemand
set_fact:
oidc_client_secret: "{{ keycloak_secret.clientsecret_info.value }}"
no_log: true
- name: Set ood_install_apps variable
set_fact:
ood_install_apps: "{{ ood_install_apps|default({}) | ansible.builtin.combine({ item.key: { 'repo': item.value.repo, 'version': item.value.version } }) }}"
with_items: "{{ ood_apps | dict2items }}"
when: item.value.enabled == true
- name: Set pinned_apps variable
set_fact:
pinned_apps: "{{ pinned_apps + [ 'sys/' + item.key ] }}"
with_items: "{{ ood_apps | dict2items }}"
when: item.value.enabled == true
vars:
pinned_apps: []
roles:
- osc.open_ondemand
- name: Post ondemand setup
hosts: webnode
become: true
vars_files:
- ondemand-config.yml
pre_tasks:
- name: Install dependencies for interactive apps
apt:
name:
- ncat
- websockify
state: present
roles:
- role: openondemand-k8s/web-node
- role: openondemand-webnode-config
- name: Install ondemand_exporter and grafana app
hosts: webnode
become: true
vars_files:
- ondemand-config.yml
roles:
- monitoring/ondemand_exporter
- monitoring/grafana_webnode
- name: Install prometheus node exporter
hosts: servers
become: true
vars_files:
- ondemand-config.yml
roles:
- prometheus.prometheus.node_exporter
- name: Install prometheus and grafana
hosts: servicesnode
become: true
vars_files:
- ondemand-config.yml
roles:
- prometheus.prometheus.prometheus
- monitoring/prometheus
- grafana.grafana.grafana
- monitoring/kube_prometheus
- name: Setup k8s nodes for containers apps
become: true
hosts: k8s_nodes
vars_files:
- ondemand-config.yml
roles:
- container-apps/k8s
- name: Setup webnode for containers apps
become: true
hosts: webnode
vars_files:
- ondemand-config.yml
roles:
- container-apps/webnode
- name: Provisioning application data to user homes
become: yes
hosts: servicesnode
vars_files:
- ondemand-config.yml
roles:
- app-data/scrnaseq
# should be a way to do this without rebooting (at the end because rebooting deletes the kubeconfig in /tmp...)
- name: Verify trainers group
become: yes
hosts: servers
tasks:
- name: Check trainer1 in trainers group
ansible.builtin.shell: groups trainer1 | grep trainers
register: trainers_group_test
failed_when: trainers_group_test.rc != 0 and trainers_group_test.rc != 1
- name: Reboot if trainer1 not in trainers group
ansible.builtin.reboot:
when: trainers_group_test.rc == 1
# at the very end so the slack notification goes after the reboot
- name: Install/run utility scripts/functions
hosts: servicesnode
become: yes
vars_files:
- ondemand-config.yml
roles:
- utils