From f19ddc68cee1b0eef36d07d3cd3e604d957f07ba Mon Sep 17 00:00:00 2001 From: Steve Brasier Date: Fri, 6 Jun 2025 11:16:29 +0000 Subject: [PATCH 1/2] pass templated fqdn to ansible --- .../tofu/control.tf | 6 +++--- .../tofu/inventory.tf | 3 ++- .../tofu/inventory.tpl | 7 +++++-- .../tofu/node_group/nodes.tf | 18 +++++++++++------- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/environments/skeleton/{{cookiecutter.environment}}/tofu/control.tf b/environments/skeleton/{{cookiecutter.environment}}/tofu/control.tf index 7e2e51470..2c7174452 100644 --- a/environments/skeleton/{{cookiecutter.environment}}/tofu/control.tf +++ b/environments/skeleton/{{cookiecutter.environment}}/tofu/control.tf @@ -4,7 +4,7 @@ locals { [for v in data.openstack_blockstorage_volume_v3.state: v], [for v in data.openstack_blockstorage_volume_v3.home: v] ) - nodename = templatestring( + control_fqdn = templatestring( var.cluster_nodename_template, { node = "control", @@ -38,7 +38,7 @@ resource "openstack_networking_port_v2" "control" { resource "openstack_compute_instance_v2" "control" { - name = split(".", local.nodename)[0] + name = split(".", local.control_fqdn)[0] image_id = var.cluster_image_id flavor_name = var.control_node_flavor key_pair = var.key_pair @@ -80,7 +80,7 @@ resource "openstack_compute_instance_v2" "control" { user_data = <<-EOF #cloud-config - fqdn: ${local.nodename} + fqdn: ${local.control_fqdn} bootcmd: %{for volume in local.control_volumes} diff --git a/environments/skeleton/{{cookiecutter.environment}}/tofu/inventory.tf b/environments/skeleton/{{cookiecutter.environment}}/tofu/inventory.tf index 81ac46d6c..e412dd6a9 100644 --- a/environments/skeleton/{{cookiecutter.environment}}/tofu/inventory.tf +++ b/environments/skeleton/{{cookiecutter.environment}}/tofu/inventory.tf @@ -2,8 +2,9 @@ resource "local_file" "hosts" { content = templatefile("${path.module}/inventory.tpl", { "cluster_name": var.cluster_name, - "cluster_domain_suffix": var.cluster_domain_suffix, + "cluster_domain_suffix": var.cluster_domain_suffix "control": openstack_compute_instance_v2.control + "control_fqhn": local.control_fqdn "login_groups": module.login "compute_groups": module.compute "state_dir": var.state_dir diff --git a/environments/skeleton/{{cookiecutter.environment}}/tofu/inventory.tpl b/environments/skeleton/{{cookiecutter.environment}}/tofu/inventory.tpl index bdc0b52ea..3b7cb2163 100644 --- a/environments/skeleton/{{cookiecutter.environment}}/tofu/inventory.tpl +++ b/environments/skeleton/{{cookiecutter.environment}}/tofu/inventory.tpl @@ -11,18 +11,20 @@ control: ansible_host: ${control.access_ip_v4} instance_id: ${control.id} networks: ${jsonencode({for n in control.network: n.name => {"fixed_ip_v4": n.fixed_ip_v4, "fixed_ip_v6": n.fixed_ip_v6}})} + node_fqdn: ${control_fqhn} vars: appliances_state_dir: ${state_dir} # NB needs to be set on group not host otherwise it is ignored in packer build! %{ for group_name in keys(login_groups) ~} ${cluster_name}_${group_name}: hosts: -%{ for node in login_groups[group_name]["compute_instances"] ~} +%{ for nodename, node in login_groups[group_name]["compute_instances"] ~} ${ node.name }: ansible_host: ${node.access_ip_v4} instance_id: ${ node.id } image_id: ${ node.image_id } networks: ${jsonencode({for n in node.network: n.name => {"fixed_ip_v4": n.fixed_ip_v4, "fixed_ip_v6": n.fixed_ip_v6}})} + node_fqdn: ${login_groups[group_name]["fqdns"][nodename]} %{ endfor ~} %{ endfor ~} @@ -35,11 +37,12 @@ login: %{ for group_name in keys(compute_groups) ~} ${cluster_name}_${group_name}: hosts: -%{ for node in compute_groups[group_name]["compute_instances"] ~} +%{ for nodename, node in compute_groups[group_name]["compute_instances"] ~} ${ node.name }: ansible_host: ${node.access_ip_v4} instance_id: ${ node.id } networks: ${jsonencode({for n in node.network: n.name => {"fixed_ip_v4": n.fixed_ip_v4, "fixed_ip_v6": n.fixed_ip_v6}})} + node_fqdn: ${compute_groups[group_name]["fqdns"][nodename]} %{ endfor ~} vars: # NB: this is the target image, not necessarily what is provisioned diff --git a/environments/skeleton/{{cookiecutter.environment}}/tofu/node_group/nodes.tf b/environments/skeleton/{{cookiecutter.environment}}/tofu/node_group/nodes.tf index 5e8449381..818dd95ab 100644 --- a/environments/skeleton/{{cookiecutter.environment}}/tofu/node_group/nodes.tf +++ b/environments/skeleton/{{cookiecutter.environment}}/tofu/node_group/nodes.tf @@ -13,8 +13,8 @@ locals { # Workaround for lifecycle meta-argument only taking static values compute_instances = var.ignore_image_changes ? openstack_compute_instance_v2.compute_fixed_image : openstack_compute_instance_v2.compute - # Define nodenames here to avoid repetition - nodenames = { + # Define fully qualified nodenames here to avoid repetition + fqdns = { for n in var.nodes: n => templatestring( var.nodename_template, { @@ -74,7 +74,7 @@ resource "openstack_compute_instance_v2" "compute_fixed_image" { for_each = var.ignore_image_changes ? toset(var.nodes) : [] - name = split(".", local.nodenames[each.key])[0] + name = split(".", local.fqdns[each.key])[0] image_id = var.image_id flavor_name = var.flavor key_pair = var.key_pair @@ -112,7 +112,7 @@ resource "openstack_compute_instance_v2" "compute_fixed_image" { user_data = <<-EOF #cloud-config - fqdn: ${local.nodenames[each.key]} + fqdn: ${local.fqdns[each.key]} EOF availability_zone = var.match_ironic_node ? "${var.availability_zone}::${var.baremetal_nodes[each.key]}" : null @@ -129,7 +129,7 @@ resource "openstack_compute_instance_v2" "compute" { for_each = var.ignore_image_changes ? [] : toset(var.nodes) - name = split(".", local.nodenames[each.key])[0] + name = split(".", local.fqdns[each.key])[0] image_id = var.image_id flavor_name = var.flavor key_pair = var.key_pair @@ -167,7 +167,7 @@ resource "openstack_compute_instance_v2" "compute" { user_data = <<-EOF #cloud-config - fqdn: ${local.nodenames[each.key]} + fqdn: ${local.fqdns[each.key]} EOF availability_zone = var.match_ironic_node ? "${var.availability_zone}::${var.baremetal_nodes[each.key]}" : null @@ -183,9 +183,13 @@ resource "openstack_networking_floatingip_associate_v2" "fip" { } output "compute_instances" { - value = local.compute_instances + value = local.compute_instances } output "image_id" { value = var.image_id } + +output "fqdns" { + value = local.fqdns +} From e33ae6a8d3031003a4eb4b33e32c1b8d87950a53 Mon Sep 17 00:00:00 2001 From: Steve Brasier Date: Fri, 20 Jun 2025 15:27:09 +0000 Subject: [PATCH 2/2] make fqdn/fqhn consistent --- .../skeleton/{{cookiecutter.environment}}/tofu/inventory.tf | 2 +- .../skeleton/{{cookiecutter.environment}}/tofu/inventory.tpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/environments/skeleton/{{cookiecutter.environment}}/tofu/inventory.tf b/environments/skeleton/{{cookiecutter.environment}}/tofu/inventory.tf index e412dd6a9..521b2b931 100644 --- a/environments/skeleton/{{cookiecutter.environment}}/tofu/inventory.tf +++ b/environments/skeleton/{{cookiecutter.environment}}/tofu/inventory.tf @@ -4,7 +4,7 @@ resource "local_file" "hosts" { "cluster_name": var.cluster_name, "cluster_domain_suffix": var.cluster_domain_suffix "control": openstack_compute_instance_v2.control - "control_fqhn": local.control_fqdn + "control_fqdn": local.control_fqdn "login_groups": module.login "compute_groups": module.compute "state_dir": var.state_dir diff --git a/environments/skeleton/{{cookiecutter.environment}}/tofu/inventory.tpl b/environments/skeleton/{{cookiecutter.environment}}/tofu/inventory.tpl index 3b7cb2163..081bfe24c 100644 --- a/environments/skeleton/{{cookiecutter.environment}}/tofu/inventory.tpl +++ b/environments/skeleton/{{cookiecutter.environment}}/tofu/inventory.tpl @@ -11,7 +11,7 @@ control: ansible_host: ${control.access_ip_v4} instance_id: ${control.id} networks: ${jsonencode({for n in control.network: n.name => {"fixed_ip_v4": n.fixed_ip_v4, "fixed_ip_v6": n.fixed_ip_v6}})} - node_fqdn: ${control_fqhn} + node_fqdn: ${control_fqdn} vars: appliances_state_dir: ${state_dir} # NB needs to be set on group not host otherwise it is ignored in packer build!