Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_fqdn": local.control_fqdn
"login_groups": module.login
"compute_groups": module.compute
"state_dir": var.state_dir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_fqdn}
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 ~}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Loading