我正在尝试调用IP(ipv4_address)以执行Ansible。当我运行计划/应用程序时,收到错误消息:“索引无效:给定键无法标识此集合值中的元素。”
我的配置:
resource "vsphere_virtual_machine" "vm" {
resource_pool_id = data.vsphere_compute_cluster.cluster.resource_pool_id
datastore_id = data.vsphere_datastore.datastore.id
network_interface { network_id = data.vsphere_network.network.id }
name= "terraform-test"
num_cpus = 2
memory = 4096
guest_id = "centos8_64Guest"
memory_hot_add_enabled = true
cpu_hot_add_enabled = true
cpu_hot_remove_enabled = true
disk {
label = "disk0"
size = 20
}
clone {
template_uuid = data.vsphere_virtual_machine.template.id
customize {
linux_options {
host_name = "terraform-test"
domain = "local"
time_zone = "Europe/Madrid"
}
network_interface {
ipv4_address = "10.20.30.25
ipv4_netmask = 22
dns_server_list = ["8.8.8.8"]
}
ipv4_gateway = "10.20.30.1"
}
}
provisioner "local-exec" {
command = "sleep 60; ansible-playbook configure.yml -i '${self.clone[4]}',"
}
}
我的目标是在刚刚使用IP 10.20.30.25创建的服务器上运行Playbook。
如何获取vsphere_virtual_machine的IP来运行ansible-playbook?
答案 0 :(得分:1)
巩固@Helder Sapulveda的指导,从对问题的评论到答案以供将来参考:
provisioner "local-exec" {
command = "sleep 60; ansible-playbook configure.yml -i '${self.default_ip_address}',"
}
您可以使用default_ip_address attribute of vsphere_virtual_machine来获取ansible-playbook命令的IP地址。