克隆虚拟机时出错:等待克隆完成的超时

时间:2019-10-03 09:32:08

标签: terraform vsphere

我当前正在使用Terraform将多个VM部署到我的vSphere中。 问题是我正在使用clone语句在我的vms中设置静态ip,但出现以下错误:克隆虚拟机时出错:超时等待克隆完成

我当前正在使用terraform版本v0.11.7,而我的vSphere版本是6.5

resource "vsphere_virtual_machine" "master" {

  guest_id = "${data.vsphere_virtual_machine.template.guest_id}" 
resource_pool_id = "${data.vsphere_compute_cluster.cluster.resource_pool_id}"
datastore_id = "${data.vsphere_datastore.datastore.id}"

count = "${length(var.vms_master)}"

network_interface {
    network_id = "${data.vsphere_network.network.id}"
    adapter_type = "${data.vsphere_virtual_machine.template.network_interface_types[0]}"
}

  name = "${var.vms_master[count.index]}"
  datastore_id = "${data.vsphere_datastore.datastore.id}"

  disk {
    label="default_disk"
    size             = "${data.vsphere_virtual_machine.template.disks.0.size}"
    eagerly_scrub    = "${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}"
    thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}"
    unit_number=0  
}

  disk {
      size = "100"
      label = "${var.vms_master[count.index]}_1"
      thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}"
      eagerly_scrub    = "${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}"
        unit_number=2   
 }
  disk {
      size = "10"
      label = "${var.vms_master[count.index]}_2"
      thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}"
      eagerly_scrub    = "${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}"
        unit_number=3   
 }

  folder = "${vsphere_folder.master.path}"
  memory = 512
  num_cpus = 1
  wait_for_guest_ip_timeout = "0" #el laboratorio va muy lento... entonces el timeout se da antes de q la vm este creada!
  wait_for_guest_net_timeout = "0"

clone {
    template_uuid = "${data.vsphere_virtual_machine.template.id}"
    linked_clone  = "${var.vm_linked_clone}"

    customize {
      //timeout = "0"
  timeouts {
    create = "5s"
    delete = "2h"
  }
      linux_options {
        host_name = "${var.vms_hostname_master[count.index]}"
        domain    = "$ocp.essi.lab"
      }
      network_interface {
        ipv4_address = "${var.ip_list_master[count.index]}"          
        ipv4_netmask = "24"
      }

      ipv4_gateway    ="172.16.1.1"
      dns_server_list = ["${var.dns_servers}"]
    }   
}
}

预期结果: 将虚拟机部署到vSphere中

实际结果: 前述错误: 克隆虚拟机时出错:等待克隆完成的超时时间

谢谢大家的见解! :)

1 个答案:

答案 0 :(得分:0)

解决方法非常简单,我只需要再添加一条超时行:

resource "vsphere_virtual_machine" "master" {

  guest_id = "${data.vsphere_virtual_machine.template.guest_id}" 
resource_pool_id = "${data.vsphere_compute_cluster.cluster.resource_pool_id}"
datastore_id = "${data.vsphere_datastore.datastore.id}"

count = "${length(var.vms_master)}"

network_interface {
    network_id = "${data.vsphere_network.network.id}"
    adapter_type = "${data.vsphere_virtual_machine.template.network_interface_types[0]}"
}

  name = "${var.vms_master[count.index]}"
  datastore_id = "${data.vsphere_datastore.datastore.id}"

  disk {
    label="default_disk"
    size             = "${data.vsphere_virtual_machine.template.disks.0.size}"
    eagerly_scrub    = "${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}"
    thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}"
    unit_number=0  
}

  disk {
      size = "100"
      label = "${var.vms_master[count.index]}_1"
      thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}"
      eagerly_scrub    = "${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}"
        unit_number=2   
 }
  disk {
      size = "10"
      label = "${var.vms_master[count.index]}_2"
      thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}"
      eagerly_scrub    = "${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}"
        unit_number=3   
 }

  folder = "${vsphere_folder.master.path}"
  memory = 512
  num_cpus = 1
  wait_for_guest_ip_timeout = "0" #el laboratorio va muy lento... entonces el timeout se da antes de q la vm este creada!
  wait_for_guest_net_timeout = "0"

clone {
    template_uuid = "${data.vsphere_virtual_machine.template.id}"
    linked_clone  = "${var.vm_linked_clone}"
      timeout = "0"   //NEW LINE ADDED

    customize {
      timeout = "0"
  timeouts {
    create = "5s"
    delete = "2h"
  }
      linux_options {
        host_name = "${var.vms_hostname_master[count.index]}"
        domain    = "$ocp.essi.lab"
      }
      network_interface {
        ipv4_address = "${var.ip_list_master[count.index]}"          
        ipv4_netmask = "24"
      }

      ipv4_gateway    ="172.16.1.1"
      dns_server_list = ["${var.dns_servers}"]
    }   
}
}