Skip to content

Commit 776d5df

Browse files
authored
Merge pull request #11 from stackhpc/feature/image-patch
Make patch image-based
2 parents dcdb6ab + 63a2e9a commit 776d5df

File tree

13 files changed

+122
-26
lines changed

13 files changed

+122
-26
lines changed

group_vars/cluster.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ appliances_local_users_podman_enable: "{{ groups.get('podman', []) | length > 0
1717
# The server name for Open OnDemand depends on whether Zenith is enabled or not
1818
openondemand_servername_default: "{{ hostvars[groups['openstack'][0]].cluster_floating_ip_address | replace('.', '-') ~ '.sslip.io' }}"
1919
openondemand_servername: "{{ zenith_fqdn_ood | default(openondemand_servername_default) }}"
20+
21+
appliances_state_dir: /var/lib/state

group_vars/control.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

group_vars/nfs.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
11
# Use the IP address instead
2-
nfs_server_default: "{{ hostvars[groups['control'] | first ].ansible_default_ipv4.address }}"
2+
nfs_server: "{{ hostvars[groups['control'] | first ].ansible_default_ipv4.address }}"
3+
4+
nfs_configurations:
5+
- comment: Export /exports/home from Slurm control node as /home
6+
nfs_enable:
7+
server: "{{ inventory_hostname in groups['control'] }}"
8+
clients: "{{ inventory_hostname in groups['cluster'] and inventory_hostname not in groups['control'] }}"
9+
nfs_export: "/exports/home" # assumes skeleton TF is being used
10+
nfs_client_mnt_point: "/home"
11+
- comment: Export /var/lib/state from Slurm control node to OOD
12+
nfs_enable:
13+
server: "{{ inventory_hostname in groups['control'] }}"
14+
clients: "{{ inventory_hostname in groups['openondemand'] }}"
15+
nfs_export: "{{ appliances_state_dir }}"
16+
nfs_client_mnt_point: "{{ appliances_state_dir }}"
17+
nfs_client_mnt_options: "x-systemd.required-by=zenith-ood.service,x-systemd.before=zenith-ood.service"

group_vars/openondemand.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,3 @@ _opeonondemand_unset_auth: ' RequestHeader unset Authorization'
7373

7474
# Fix grafana proxying for basic auth if anonymous grafana access enabled:
7575
openondemand_node_proxy_directives: "{{ _opeonondemand_unset_auth if (openondemand_auth == 'basic_pam' and 'openondemand_host_regex' and 'grafana' in groups and hostvars[groups['grafana'][0]]._grafana_auth_is_anonymous) else '' }}"
76-
77-

requirements.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ collections:
4040
- name: openstack.cloud
4141
- name: https://github.com/stackhpc/ansible-collection-terraform
4242
type: git
43-
version: ae1dc46a9d266bcdc6e79a6e290edbb080596f7f
43+
version: 75fb75132bbc77e3e78a05ba674458131da2b1dd
4444

roles/cluster_infra/tasks/main.yml

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
- debug:
2+
msg: |
3+
terraform_backend_type: {{ terraform_backend_type }}
4+
terraform_state: {{ terraform_state }}
5+
cluster_upgrade_system_packages: {{ cluster_upgrade_system_packages | default('undefined') }}
6+
17
# We need to convert the floating IP id to an address for Terraform
28
- name: Look up floating IP
39
include_role:
@@ -10,11 +16,42 @@
1016
set_fact:
1117
cluster_floating_ip_address: "{{ os_floating_ip_info.floating_ip_address }}"
1218

19+
- name: Install Terraform binary
20+
include_role:
21+
name: stackhpc.terraform.install
22+
1323
- name: Make Terraform project directory
1424
file:
1525
path: "{{ terraform_project_path }}"
1626
state: directory
1727

28+
- name: Write backend configuration
29+
copy:
30+
content: |
31+
terraform {
32+
backend "{{ terraform_backend_type }}" { }
33+
}
34+
dest: "{{ terraform_project_path }}/backend.tf"
35+
36+
# Patching in this appliance is implemented as a switch to a new base image
37+
# So unless explicitly patching, we want to use the same image as last time
38+
# To do this, we query the previous Terraform state before updating
39+
- block:
40+
- name: Get previous Terraform state
41+
stackhpc.terraform.terraform_output:
42+
binary_path: "{{ terraform_binary_path }}"
43+
project_path: "{{ terraform_project_path }}"
44+
backend_config: "{{ terraform_backend_config }}"
45+
register: cluster_infra_terraform_output
46+
47+
- name: Extract image from Terraform state
48+
set_fact:
49+
cluster_previous_image: "{{ cluster_infra_terraform_output.outputs.cluster_image.value }}"
50+
when: '"cluster_image" in cluster_infra_terraform_output.outputs'
51+
when:
52+
- terraform_state == "present"
53+
- cluster_upgrade_system_packages is not defined or not cluster_upgrade_system_packages
54+
1855
- name: Template Terraform files into project directory
1956
template:
2057
src: "{{ item }}.j2"
@@ -24,10 +61,6 @@
2461
- providers.tf
2562
- resources.tf
2663

27-
- name: Install Terraform binary
28-
include_role:
29-
name: stackhpc.terraform.install
30-
3164
- name: Provision infrastructure
3265
include_role:
3366
name: stackhpc.terraform.infra

roles/cluster_infra/templates/outputs.tf.j2

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ output "cluster_nodes" {
3636
]
3737
)
3838
}
39+
40+
output "cluster_image" {
41+
description = "The id of the image used to build the cluster nodes"
42+
value = "{{ cluster_previous_image | default(cluster_image) }}"
43+
}

roles/cluster_infra/templates/resources.tf.j2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ resource "openstack_blockstorage_volume_v3" "home" {
9191

9292
resource "openstack_compute_instance_v2" "login" {
9393
name = "{{ cluster_name }}-login-0"
94-
image_id = "{{ cluster_image }}"
94+
image_id = "{{ cluster_previous_image | default(cluster_image) }}"
9595
{% if login_flavor_name is defined %}
9696
flavor_name = "{{ login_flavor_name }}"
9797
{% else %}
@@ -116,7 +116,7 @@ resource "openstack_compute_instance_v2" "login" {
116116

117117
resource "openstack_compute_instance_v2" "control" {
118118
name = "{{ cluster_name }}-control-0"
119-
image_id = "{{ cluster_image }}"
119+
image_id = "{{ cluster_previous_image | default(cluster_image) }}"
120120
{% if control_flavor_name is defined %}
121121
flavor_name = "{{ control_flavor_name }}"
122122
{% else %}
@@ -169,7 +169,7 @@ resource "openstack_compute_instance_v2" "control" {
169169
device: /dev/{{ block_device_prefix }}c
170170
partition: auto
171171
mounts:
172-
- [LABEL=state, /var/lib/state]
172+
- [LABEL=state, /var/lib/state, auto, "x-systemd.required-by=nfs-server.service,x-systemd.before=nfs-server.service"]
173173
- [LABEL=home, /exports/home, auto, "x-systemd.required-by=nfs-server.service,x-systemd.before=nfs-server.service"]
174174
EOF
175175
}
@@ -178,7 +178,7 @@ resource "openstack_compute_instance_v2" "compute" {
178178
count = {{ compute_count }}
179179

180180
name = "{{ cluster_name }}-compute-${count.index}"
181-
image_id = "{{ cluster_image }}"
181+
image_id = "{{ cluster_previous_image | default(cluster_image) }}"
182182
flavor_id = "{{ compute_flavor }}"
183183

184184
network {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
3+
- name: Ensure hostkeys directory exists on persistent storage
4+
file:
5+
path: "{{ appliances_state_dir }}/hostkeys/{{ inventory_hostname }}"
6+
state: directory
7+
owner: root
8+
group: root
9+
mode: 0600
10+
11+
- name: Copy hostkeys from persistent storage
12+
# won't fail if no keys are in persistent storage
13+
copy:
14+
src: "{{ appliances_state_dir }}/hostkeys/{{ inventory_hostname }}/"
15+
dest: /etc/ssh/
16+
remote_src: true
17+
18+
- name: Find hostkeys
19+
find:
20+
path: /etc/ssh/
21+
patterns: ssh_host_*_key*
22+
register: _find_ssh_keys
23+
24+
- name: Persist hostkeys
25+
copy:
26+
dest: "{{ appliances_state_dir }}/hostkeys/{{ inventory_hostname }}/"
27+
src: "{{ item }}"
28+
remote_src: true
29+
mode: preserve
30+
loop: "{{ _find_ssh_keys.files | map(attribute='path') }}"
31+
32+
- meta: reset_connection
33+

roles/persist_openhpc_secrets/tasks/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22

3-
- name: Check if OpenHPC secrets exist
3+
- name: Check if OpenHPC secrets exist in persistent storage
44
stat:
55
path: "{{ appliances_state_dir }}/ansible.facts.d/openhpc_secrets.fact"
66
register: openhpc_secrets_stat
@@ -32,4 +32,4 @@
3232

3333
- name: Read facts
3434
ansible.builtin.setup:
35-
filter: ansible_local
35+
filter: ansible_local

0 commit comments

Comments
 (0)