Skip to content

Commit 215fcbc

Browse files
authored
Merge pull request #29 from stackhpc/feat/ssh-key-customisation
Make cluster deploy SSH keys more flexible
2 parents e954e6e + d811e67 commit 215fcbc

File tree

5 files changed

+78
-4
lines changed

5 files changed

+78
-4
lines changed

group_vars/openstack.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ cluster_ssh_user: rocky
1919

2020
# Set the size of the state volume to metrics_db_maximum_size + 10
2121
state_volume_size: "{{ metrics_db_maximum_size + 10 }}"
22-
block_device_prefix: 'vd'

roles/cluster_infra/defaults/main.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,11 @@ cluster_groups_validation:
5050
cluster_groups_zenith:
5151
# Any hosts in the grafana and openondemand groups should go in the zenith group
5252
zenith: [grafana, openondemand]
53+
54+
cluster_deploy_ssh_keys_extra: []
55+
56+
# List of hw_scsi_models that result in block devices presenting as /dev/sdX
57+
# rather than /dev/vdX
58+
scsi_models:
59+
# Ceph [https://docs.ceph.com/en/quincy/rbd/rbd-openstack/#image-properties]
60+
- virtio-scsi

roles/cluster_infra/tasks/main.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@
5757
- terraform_state == "present"
5858
- cluster_upgrade_system_packages is not defined or not cluster_upgrade_system_packages
5959

60+
- name: Detect volume device prefix from image metadata
61+
block:
62+
- name: Get image metadata from OpenStack API
63+
openstack.cloud.image_info:
64+
image: "{{ cluster_previous_image | default(cluster_image) }}"
65+
register: cluster_image_info
66+
67+
- name: Set volume_device_prefix fact
68+
set_fact:
69+
block_device_prefix: >-
70+
{{
71+
'sd' if cluster_image_info.image.metadata.hw_scsi_model is defined and
72+
cluster_image_info.image.metadata.hw_scsi_model in scsi_models
73+
else 'vd'
74+
}}
75+
# Only run when block_device_prefix isn't set as an extravar
76+
when: block_device_prefix is not defined
77+
78+
6079
- name: Template Terraform files into project directory
6180
template:
6281
src: >-

roles/cluster_infra/templates/outputs.tf.j2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ output "cluster_gateway_ip" {
33
value = openstack_compute_floatingip_associate_v2.login_floatingip_assoc.floating_ip
44
}
55

6+
{% if cluster_ssh_private_key_file is not defined %}
7+
output "cluster_ssh_private_key" {
8+
description = "The private component of the keypair generated on cluster provision"
9+
value = openstack_compute_keypair_v2.cluster_keypair.private_key
10+
sensitive = true
11+
}
12+
{% endif %}
13+
614
output "cluster_nodes" {
715
description = "A list of the nodes in the cluster from which an Ansible inventory will be populated"
816
value = concat(

roles/cluster_infra/templates/resources.tf.j2

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#jinja2: trim_blocks:False
12
#####
23
##### The identity scope we are operating in
34
##### Used to output the OpenStack project ID as a fact for provisioned hosts
@@ -233,6 +234,14 @@ resource "openstack_networking_port_v2" "{{ partition.name }}" {
233234

234235
{% endfor %}
235236

237+
#####
238+
##### Deploy key
239+
#####
240+
{% if cluster_ssh_private_key_file is not defined %}
241+
resource "openstack_compute_keypair_v2" "cluster_keypair" {
242+
name = "{{ cluster_name }}-deploy-key"
243+
}
244+
{% endif %}
236245

237246
#####
238247
##### Cluster nodes
@@ -255,8 +264,18 @@ resource "openstack_compute_instance_v2" "login" {
255264
user_data = <<-EOF
256265
#cloud-config
257266
ssh_authorized_keys:
258-
- {{ cluster_deploy_ssh_public_key }}
267+
{%- if cluster_user_ssh_public_key is defined %}
259268
- {{ cluster_user_ssh_public_key }}
269+
{%- endif %}
270+
{%- if cluster_deploy_ssh_public_key is defined %}
271+
- {{ cluster_deploy_ssh_public_key }}
272+
{%- endif %}
273+
{%- if cluster_ssh_private_key_file is not defined %}
274+
- "${openstack_compute_keypair_v2.cluster_keypair.public_key}"
275+
{%- endif %}
276+
{%- for ssh_key in cluster_deploy_ssh_keys_extra %}
277+
- {{ ssh_key }}
278+
{%- endfor %}
260279
EOF
261280
}
262281

@@ -302,8 +321,18 @@ resource "openstack_compute_instance_v2" "control" {
302321
user_data = <<-EOF
303322
#cloud-config
304323
ssh_authorized_keys:
305-
- {{ cluster_deploy_ssh_public_key }}
324+
{%- if cluster_user_ssh_public_key is defined %}
306325
- {{ cluster_user_ssh_public_key }}
326+
{%- endif %}
327+
{%- if cluster_deploy_ssh_public_key is defined %}
328+
- {{ cluster_deploy_ssh_public_key }}
329+
{%- endif %}
330+
{%- if cluster_ssh_private_key_file is not defined %}
331+
- "${openstack_compute_keypair_v2.cluster_keypair.public_key}"
332+
{%- endif %}
333+
{%- for ssh_key in cluster_deploy_ssh_keys_extra %}
334+
- {{ ssh_key }}
335+
{%- endfor %}
307336
fs_setup:
308337
- label: state
309338
filesystem: ext4
@@ -335,10 +364,21 @@ resource "openstack_compute_instance_v2" "{{ partition.name }}" {
335364
user_data = <<-EOF
336365
#cloud-config
337366
ssh_authorized_keys:
338-
- {{ cluster_deploy_ssh_public_key }}
367+
{%- if cluster_user_ssh_public_key is defined %}
339368
- {{ cluster_user_ssh_public_key }}
369+
{%- endif %}
370+
{%- if cluster_deploy_ssh_public_key is defined %}
371+
- {{ cluster_deploy_ssh_public_key }}
372+
{%- endif %}
373+
{%- if cluster_ssh_private_key_file is not defined %}
374+
- "${openstack_compute_keypair_v2.cluster_keypair.public_key}"
375+
{%- endif %}
376+
{%- for ssh_key in cluster_deploy_ssh_keys_extra %}
377+
- {{ ssh_key }}
378+
{%- endfor %}
340379
EOF
341380
}
381+
342382
{% endfor %}
343383

344384
#####

0 commit comments

Comments
 (0)