diff --git a/ansible_inventory.tmpl b/ansible_inventory.tmpl index 6456a504985dc354f15653ebfe9746c5e38a6674..3cf786d334f49fb91e74a1bb3f0ff834930076cd 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 42f8aa524a81ff4ee360b34ceb67418c5880f3c6..d13f731298f815f8e1d1951866e789bc69a18dd6 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 }