From 0dc5a91032ce81ea9a63da0203867c1864b7acf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ing=2E=20Kl=C3=A1ra=20Moravcov=C3=A1?= <klara.moravcova@cesnet.cz> Date: Wed, 25 Oct 2023 15:53:06 +0200 Subject: [PATCH] Modify inventory to use instance name. --- ansible_inventory.tmpl | 24 ++++++++++++------------ inventory.tf | 4 +++- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/ansible_inventory.tmpl b/ansible_inventory.tmpl index 6456a50..3cf786d 100644 --- a/ansible_inventory.tmpl +++ b/ansible_inventory.tmpl @@ -1,10 +1,10 @@ [all] -%{ for index,ip in k8s_master_ip ~} -control${index+1} ansible_host=${ip} +%{ for i, name in k8s_control_name ~} +${name} ansible_host=${element(k8s_control_ip, i)} %{ endfor ~} -%{ for index,ip in k8s_worker_ip ~} -node${index+1} ansible_host=${ip} +%{ for i, name in k8s_worker_name ~} +${name} ansible_host=${element(k8s_worker_ip, i)} %{ endfor ~} ## configure a bastion host if your nodes are not directly reachable @@ -12,21 +12,21 @@ node${index+1} ansible_host=${ip} bastion ansible_host=${k8s_bastion_ip} ansible_user=${bastion_ssh_user_name} [kube_control_plane] -%{ for index,ip in k8s_master_ip ~} -control${index+1} +%{ for name in k8s_control_name ~} +${name} %{ endfor ~} [etcd] -%{ for index,ip in k8s_master_ip ~} -control${index+1} +%{ for name in k8s_control_name ~} +${name} %{ endfor ~} [kube_node] -%{ for index,ip in k8s_master_ip ~} -control${index+1} +%{ for name in k8s_control_name ~} +${name} %{ endfor ~} -%{ for index,ip in k8s_worker_ip ~} -node${index+1} +%{ for name in k8s_worker_name ~} +${name} %{ endfor ~} [calico_rr] diff --git a/inventory.tf b/inventory.tf index 42f8aa5..d13f731 100644 --- a/inventory.tf +++ b/inventory.tf @@ -3,7 +3,9 @@ resource "local_file" "k8s_file" { { bastion_ssh_user_name = var.bastion_ssh_user_name k8s_bastion_ip = openstack_networking_floatingip_v2.bastion_fip.address - k8s_control_ip = openstack_compute_instance_v2.control_nodes.*.access_ip_v4 + k8s_control_name = openstack_compute_instance_v2.control_nodes.*.name + k8s_control_ip = openstack_compute_instance_v2.control_nodes.*.access_ip_v4 + k8s_worker_name = openstack_compute_instance_v2.worker_nodes.*.name k8s_worker_ip = openstack_compute_instance_v2.worker_nodes.*.access_ip_v4 } -- GitLab