Skip to content

Commit e1de488

Browse files
sjpbbertiethorpe
andauthored
Pass templated fqdn to ansible (#702)
* pass templated fqdn to ansible * make fqdn/fqhn consistent --------- Co-authored-by: bertiethorpe <[email protected]>
1 parent 5f2f931 commit e1de488

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",
@@ -38,7 +38,7 @@ resource "openstack_networking_port_v2" "control" {
3838

3939
resource "openstack_compute_instance_v2" "control" {
4040

41-
name = split(".", local.nodename)[0]
41+
name = split(".", local.control_fqdn)[0]
4242
image_id = var.cluster_image_id
4343
flavor_name = var.control_node_flavor
4444
key_pair = var.key_pair
@@ -80,7 +80,7 @@ resource "openstack_compute_instance_v2" "control" {
8080

8181
user_data = <<-EOF
8282
#cloud-config
83-
fqdn: ${local.nodename}
83+
fqdn: ${local.control_fqdn}
8484
8585
bootcmd:
8686
%{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_fqdn": 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_fqdn}
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
{
@@ -74,7 +74,7 @@ resource "openstack_compute_instance_v2" "compute_fixed_image" {
7474

7575
for_each = var.ignore_image_changes ? toset(var.nodes) : []
7676

77-
name = split(".", local.nodenames[each.key])[0]
77+
name = split(".", local.fqdns[each.key])[0]
7878
image_id = var.image_id
7979
flavor_name = var.flavor
8080
key_pair = var.key_pair
@@ -112,7 +112,7 @@ resource "openstack_compute_instance_v2" "compute_fixed_image" {
112112

113113
user_data = <<-EOF
114114
#cloud-config
115-
fqdn: ${local.nodenames[each.key]}
115+
fqdn: ${local.fqdns[each.key]}
116116
EOF
117117

118118
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" {
129129

130130
for_each = var.ignore_image_changes ? [] : toset(var.nodes)
131131

132-
name = split(".", local.nodenames[each.key])[0]
132+
name = split(".", local.fqdns[each.key])[0]
133133
image_id = var.image_id
134134
flavor_name = var.flavor
135135
key_pair = var.key_pair
@@ -167,7 +167,7 @@ resource "openstack_compute_instance_v2" "compute" {
167167

168168
user_data = <<-EOF
169169
#cloud-config
170-
fqdn: ${local.nodenames[each.key]}
170+
fqdn: ${local.fqdns[each.key]}
171171
EOF
172172

173173
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" {
183183
}
184184

185185
output "compute_instances" {
186-
value = local.compute_instances
186+
value = local.compute_instances
187187
}
188188

189189
output "image_id" {
190190
value = var.image_id
191191
}
192+
193+
output "fqdns" {
194+
value = local.fqdns
195+
}

0 commit comments

Comments
 (0)