-
Notifications
You must be signed in to change notification settings - Fork 5
/
create_compute_image.yml
237 lines (200 loc) · 6.35 KB
/
create_compute_image.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
---
- hosts: localhost
gather_facts: false
vars_files:
- ./vars/main.yml
tasks:
- name: Check if compute node image already exists
openstack.cloud.image_info:
image: "{{ compute_node_image }}"
register: compute_image_info
- fail:
msg: "{{ compute_node_image }} already exists."
when: compute_image_info.openstack_images
- name: Get size of the image
os_image_info:
image: "{{ image_name }}"
register: image_info
- name: Create boot volume for compute imaging instance
os_volume:
name: "{{ compute_node_image }}"
image: "{{ image_name }}"
size: "{{ (image_info.openstack_images[0].size/1024/1024/1024) | int }}"
bootable: true
state: present
- name: Launch compute imaging instance
os_server:
name: "{{ cluster_name }}-compute-imaging"
boot_volume: "{{ compute_node_image }}"
flavor: "{{ compute_imaging_instance_flavor }}"
key_name: "{{ keypair_name }}"
network: "{{ cluster_network_name }}"
auto_ip: yes
security_groups:
- "{{ cluster_security_group }}"
state: present
- name: Get imaging instance info
os_server_info:
server: "{{ cluster_name }}-compute-imaging"
register: compute_imaging
- name: Add imaging instance to Ansible inventory
add_host:
name: "{{ compute_imaging.openstack_servers[0].accessIPv4 }}"
groups: compute_imaging
ansible_user: "{{ image_init_user }}"
ansible_ssh_private_key_file: "{{ ssh_private_keyfile }}"
ansible_ssh_extra_args: '-o StrictHostKeyChecking=no'
changed_when: false
- import_tasks: tasks/add_headnode_inventory.yml
- hosts: compute_imaging
gather_facts: false
vars_files:
- ./vars/main.yml
tasks:
- name: Wait for compute imaging instance to boot and become reachable
wait_for_connection:
- debug:
msg: "{{ cluster_name }}_compute_imaging instance is running at {{ hostvars['localhost'].compute_imaging.openstack_servers[0].accessIPv4 }}."
- hosts: compute_imaging
gather_facts: true
vars_files:
- ./vars/main.yml
become: true
roles:
- role: geerlingguy.ntp
vars:
ntp_daemon: chronyd
ntp_timezone: "America/New_York"
ntp_enabled: true
ntp_config_file: /etc/chrony.conf
ntp_servers:
- "ntp0.cac.cornell.edu iburst"
- "ntp1.cac.cornell.edu iburst"
- "ntp2.cac.cornell.edu iburst"
ntp_cron_handler_enabled: false
tasks:
- import_tasks: tasks/install_compute_packages.yml
- name: Make sure firewall is running
service:
name: firewalld
state: started
enabled: true
- name: Allow incoming traffic from cluster network
ansible.posix.firewalld:
source: "{{ cluster_network_cidr }}"
zone: trusted
state: enabled
permanent: true
immediate: true
- name: Configure compute node to send syslog to head node
blockinfile:
path: "/etc/rsyslog.conf"
insertbefore: EOF
block: |
*.* @{{ hostvars['localhost'].headnode.openstack_servers[0].private_v4 }}:514
action(type="omfwd" Target="{{ hostvars['localhost'].headnode.openstack_servers[0].private_v4 }}" Port="514" Protocol="udp")
- name: Add home directory mount to /etc/fstab
ansible.posix.mount:
path: /home
src: "{{ hostvars['localhost'].headnode.openstack_servers[0].private_v4 }}:/home"
fstype: nfs
state: present
- name: Create /opt/ohpc/pub
file:
path: /opt/ohpc/pub
state: directory
owner: root
group: root
mode: 0755
- name: Add /opt/ohpc/pub to /etc/fstab
ansible.posix.mount:
path: /opt/ohpc/pub
src: "{{ hostvars['localhost'].headnode.openstack_servers[0].private_v4 }}:/opt/ohpc/pub"
fstype: nfs
state: present
- name: Create /opt/intel in chroot
file:
path: /opt/intel
state: directory
owner: root
group: root
mode: 0755
when: install_intel_oneapi
- name: Add NFS mount /opt/intel to chroot
lineinfile:
path: /etc/fstab
line: "{{ hostvars['localhost'].headnode.openstack_servers[0].private_v4 }}:/opt/intel /opt/intel nfs nfsvers=3,nodev 0 0"
state: present
when: install_intel_oneapi
- name: Create /var/log/slurm
file:
path: /var/log/slurm
owner: slurm
group: slurm
mode: 0700
state: directory
- name: Copy slurm.conf
template:
src: slurm.conf.j2
dest: /etc/slurm/slurm.conf
owner: root
group: root
mode: 0644
- name: Increase the number of munge daemons to 10
copy:
dest: /etc/sysconfig/munge
owner: root
group: root
mode: 0644
content: |
DAEMON_ARGS="--key-file /etc/munge/munge.key --num-threads 10"
- name: Copy munge key
copy:
src: munge.key
dest: /etc/munge/munge.key
owner: munge
group: munge
mode: 0600
- name: Set slurmd to auto-start at boot time
service:
name: slurmd
enabled: true
- name: Set munge to auto-start at boot time
service:
name: munge
enabled: true
- name: Shut down compute imaging instance
community.general.shutdown:
delay: 5
- name: Wait 10 seconds for instance shut down
pause:
seconds: 10
- hosts: localhost
gather_facts: false
vars_files:
- ./vars/main.yml
tasks:
- name: Delete compute imaging instance
openstack.cloud.server:
delete_fip: true
name: "{{ cluster_name }}-compute-imaging"
state: absent
- name: Wait for the compute image volume is detached
openstack.cloud.volume_info:
name: "{{ compute_node_image }} "
details: true
register: volumes_info
until: volumes_info.volumes[0].status is match("available")
- name: Create compute image
openstack.cloud.image:
name: "{{ compute_node_image }}"
volume: "{{ volumes_info.volumes[0].id }}"
disk_format: raw
timeout: 1200
state: present
- name: Delete compute image volume
openstack.cloud.volume:
name: "{{ volumes_info.volumes[0].id }}"
state: absent
- debug:
msg: "Created {{ compute_node_image }}."