Skip to content

Commit 55fb2fd

Browse files
committed
pass templated fqdn to ansible
1 parent e8cc51e commit 55fb2fd

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

environments/skeleton/{{cookiecutter.environment}}/tofu/control.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ locals {
44
[for v in data.openstack_blockstorage_volume_v3.state: v],
55
[for v in data.openstack_blockstorage_volume_v3.home: v]
66
)
7-
nodename = templatestring(
7+
control_fqdn = templatestring(
88
var.cluster_nodename_template,
99
{
1010
node = "control",
@@ -37,7 +37,7 @@ resource "openstack_networking_port_v2" "control" {
3737

3838
resource "openstack_compute_instance_v2" "control" {
3939

40-
name = split(".", local.nodename)[0]
40+
name = split(".", local.control_fqdn)[0]
4141
image_id = var.cluster_image_id
4242
flavor_name = var.control_node_flavor
4343
key_pair = var.key_pair
@@ -79,7 +79,7 @@ resource "openstack_compute_instance_v2" "control" {
7979

8080
user_data = <<-EOF
8181
#cloud-config
82-
fqdn: ${local.nodename}
82+
fqdn: ${local.control_fqdn}
8383
8484
bootcmd:
8585
%{for volume in local.control_volumes}

environments/skeleton/{{cookiecutter.environment}}/tofu/inventory.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ resource "local_file" "hosts" {
22
content = templatefile("${path.module}/inventory.tpl",
33
{
44
"cluster_name": var.cluster_name,
5-
"cluster_domain_suffix": var.cluster_domain_suffix,
5+
"cluster_domain_suffix": var.cluster_domain_suffix
66
"control": openstack_compute_instance_v2.control
7+
"control_fqhn": local.control_fqdn
78
"login_groups": module.login
89
"compute_groups": module.compute
910
"state_dir": var.state_dir

environments/skeleton/{{cookiecutter.environment}}/tofu/inventory.tpl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ control:
1111
ansible_host: ${control.access_ip_v4}
1212
instance_id: ${control.id}
1313
networks: ${jsonencode({for n in control.network: n.name => {"fixed_ip_v4": n.fixed_ip_v4, "fixed_ip_v6": n.fixed_ip_v6}})}
14+
node_fqdn: ${control_fqhn}
1415
vars:
1516
appliances_state_dir: ${state_dir} # NB needs to be set on group not host otherwise it is ignored in packer build!
1617

1718
%{ for group_name in keys(login_groups) ~}
1819
${cluster_name}_${group_name}:
1920
hosts:
20-
%{ for node in login_groups[group_name]["compute_instances"] ~}
21+
%{ for nodename, node in login_groups[group_name]["compute_instances"] ~}
2122
${ node.name }:
2223
ansible_host: ${node.access_ip_v4}
2324
instance_id: ${ node.id }
2425
image_id: ${ node.image_id }
2526
networks: ${jsonencode({for n in node.network: n.name => {"fixed_ip_v4": n.fixed_ip_v4, "fixed_ip_v6": n.fixed_ip_v6}})}
27+
node_fqdn: ${login_groups[group_name]["fqdns"][nodename]}
2628
%{ endfor ~}
2729
%{ endfor ~}
2830

@@ -35,11 +37,12 @@ login:
3537
%{ for group_name in keys(compute_groups) ~}
3638
${cluster_name}_${group_name}:
3739
hosts:
38-
%{ for node in compute_groups[group_name]["compute_instances"] ~}
40+
%{ for nodename, node in compute_groups[group_name]["compute_instances"] ~}
3941
${ node.name }:
4042
ansible_host: ${node.access_ip_v4}
4143
instance_id: ${ node.id }
4244
networks: ${jsonencode({for n in node.network: n.name => {"fixed_ip_v4": n.fixed_ip_v4, "fixed_ip_v6": n.fixed_ip_v6}})}
45+
node_fqdn: ${compute_groups[group_name]["fqdns"][nodename]}
4346
%{ endfor ~}
4447
vars:
4548
# NB: this is the target image, not necessarily what is provisioned

environments/skeleton/{{cookiecutter.environment}}/tofu/node_group/nodes.tf

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ locals {
1313
# Workaround for lifecycle meta-argument only taking static values
1414
compute_instances = var.ignore_image_changes ? openstack_compute_instance_v2.compute_fixed_image : openstack_compute_instance_v2.compute
1515

16-
# Define nodenames here to avoid repetition
17-
nodenames = {
16+
# Define fully qualified nodenames here to avoid repetition
17+
fqdns = {
1818
for n in var.nodes: n => templatestring(
1919
var.nodename_template,
2020
{
@@ -70,7 +70,7 @@ resource "openstack_compute_instance_v2" "compute_fixed_image" {
7070

7171
for_each = var.ignore_image_changes ? toset(var.nodes) : []
7272

73-
name = split(".", local.nodenames[each.key])[0]
73+
name = split(".", local.fqdns[each.key])[0]
7474
image_id = var.image_id
7575
flavor_name = var.flavor
7676
key_pair = var.key_pair
@@ -108,7 +108,7 @@ resource "openstack_compute_instance_v2" "compute_fixed_image" {
108108

109109
user_data = <<-EOF
110110
#cloud-config
111-
fqdn: ${local.nodenames[each.key]}
111+
fqdn: ${local.fqdns[each.key]}
112112
EOF
113113

114114
availability_zone = var.match_ironic_node ? "${var.availability_zone}::${var.baremetal_nodes[each.key]}" : null
@@ -125,7 +125,7 @@ resource "openstack_compute_instance_v2" "compute" {
125125

126126
for_each = var.ignore_image_changes ? [] : toset(var.nodes)
127127

128-
name = split(".", local.nodenames[each.key])[0]
128+
name = split(".", local.fqdns[each.key])[0]
129129
image_id = var.image_id
130130
flavor_name = var.flavor
131131
key_pair = var.key_pair
@@ -163,7 +163,7 @@ resource "openstack_compute_instance_v2" "compute" {
163163

164164
user_data = <<-EOF
165165
#cloud-config
166-
fqdn: ${local.nodenames[each.key]}
166+
fqdn: ${local.fqdns[each.key]}
167167
EOF
168168

169169
availability_zone = var.match_ironic_node ? "${var.availability_zone}::${var.baremetal_nodes[each.key]}" : null
@@ -179,9 +179,13 @@ resource "openstack_networking_floatingip_associate_v2" "fip" {
179179
}
180180

181181
output "compute_instances" {
182-
value = local.compute_instances
182+
value = local.compute_instances
183183
}
184184

185185
output "image_id" {
186186
value = var.image_id
187187
}
188+
189+
output "fqdns" {
190+
value = local.fqdns
191+
}

0 commit comments

Comments
 (0)