Skip to content

Commit 30fa68a

Browse files
committed
Make cluster deploy SSH keys more flexible
Add a cluster_deploy_ssh_additional_public_keys variable for adding a list of SSH keys to the rocky user. Create a deploy SSH key if cluster_ssh_private_key_file isn't provided and make the private part available in Terraform output.
1 parent beb917d commit 30fa68a

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

roles/cluster_infra/defaults/main.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,12 @@ 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+
# Deploy user SSH keys
55+
cluster_deploy_ssh_keys: >-
56+
{{
57+
cluster_deploy_ssh_additional_public_keys | default([]) +
58+
( [cluster_deploy_ssh_public_key]
59+
if cluster_deploy_ssh_public_key is defined
60+
else [] )
61+
}}

roles/cluster_infra/templates/outputs.tf.j2

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ 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+
}
11+
{% endif %}
12+
613
output "cluster_nodes" {
714
description = "A list of the nodes in the cluster from which an Ansible inventory will be populated"
815
value = concat(

roles/cluster_infra/templates/resources.tf.j2

Lines changed: 28 additions & 6 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,12 @@ resource "openstack_compute_instance_v2" "login" {
255264
user_data = <<-EOF
256265
#cloud-config
257266
ssh_authorized_keys:
258-
- {{ cluster_deploy_ssh_public_key }}
259-
- {{ cluster_user_ssh_public_key }}
267+
{%- if cluster_ssh_private_key_file is not defined %}
268+
- "${openstack_compute_keypair_v2.cluster_keypair.public_key}"
269+
{%- endif %}
270+
{%- for ssh_key in cluster_deploy_ssh_keys %}
271+
- {{ ssh_key }}
272+
{%- endfor %}
260273
EOF
261274
}
262275

@@ -302,8 +315,12 @@ resource "openstack_compute_instance_v2" "control" {
302315
user_data = <<-EOF
303316
#cloud-config
304317
ssh_authorized_keys:
305-
- {{ cluster_deploy_ssh_public_key }}
306-
- {{ cluster_user_ssh_public_key }}
318+
{%- if cluster_ssh_private_key_file is not defined %}
319+
- "${openstack_compute_keypair_v2.cluster_keypair.public_key}"
320+
{%- endif %}
321+
{%- for ssh_key in cluster_deploy_ssh_keys %}
322+
- {{ ssh_key }}
323+
{%- endfor %}
307324
fs_setup:
308325
- label: state
309326
filesystem: ext4
@@ -335,10 +352,15 @@ resource "openstack_compute_instance_v2" "{{ partition.name }}" {
335352
user_data = <<-EOF
336353
#cloud-config
337354
ssh_authorized_keys:
338-
- {{ cluster_deploy_ssh_public_key }}
339-
- {{ cluster_user_ssh_public_key }}
355+
{%- if cluster_ssh_private_key_file is not defined %}
356+
- "${openstack_compute_keypair_v2.cluster_keypair.public_key}"
357+
{%- endif %}
358+
{%- for ssh_key in cluster_deploy_ssh_keys %}
359+
- {{ ssh_key }}
360+
{%- endfor %}
340361
EOF
341362
}
363+
342364
{% endfor %}
343365

344366
#####

0 commit comments

Comments
 (0)