josenk / terraform-provider-esxi

Terraform-provider-esxi plugin
GNU General Public License v3.0
540 stars 154 forks source link

PXE guest seems to get provisioner hit early #79

Closed bish0polis closed 4 years ago

bish0polis commented 4 years ago

Hey folks,

I'm running into a tricky situation. My machine is defined as so:

resource "esxi_guest" "archer" {
  guest_name = "archer"
  disk_store = "cloud2-ssd-3t-1"
  guestos    = "centos-64"

  boot_disk_type = "thin"
  boot_disk_size = "20"

  memsize            = "2048"
  numvcpus           = "2"
  resource_pool_name = "/"
  power              = "on"

  network_interfaces {
    virtual_network = "VM Network"
    nic_type        = "vmxnet3"
  }

  connection {
    host        = self.ip_address
    type        = "ssh"
    user        = "root"
    password    = "s3kr!T"
    timeout     = "180s"
  }

  provisioner "remote-exec" {
    inline = [
      "echo success",
    ]
  }
}

The larger problem involves a chef provisioner, but my process goes:

  1. apply
  2. open ESXi to by-hand select proper PXE profile (this will go away once I switch to packered templates) on guest console
  3. guest launches
  4. guest begins installing
  5. PROVISIONER FIRES
  6. guest finished setup and reboots
  7. guest is now ready for provisioning
  8. guest seems to finish with taint

The issue is that the provisioner (chef, here) is firing before the host is ready.

Is there a way I've just not seen yet, where I can make the privisoning step wait for vmware-tools coming online, or somehow wait a little longer? What's everyone else doing for PXE guests?

josenk commented 4 years ago

Try increasing the guest_startup_timeout... It has worked for a few others. I haven't had a lot of feedback from others using pxe, but I use it myself (without the chef provsioner).

bish0polis commented 4 years ago

Is that a timeout for

  1. "wait for vmtools or just start hammering port 22" or is it
  2. "wait a while, ignoring vmtools status, and after the timeout start hammering port 22" or
  3. "if there's no vmtools by this moment, then error out"

?

I looked for it in the source, but I'm still a bit of an idiot with go and the layout.

If it's the first kind of timeout, then that may be exactly what I need. I'll try it and report the good news back. Thanks!

josenk commented 4 years ago

It's in the README... guest_startup_timeout - Optional - The amount of guest uptime, in seconds, to wait for an available IP address on this virtual machine.

When the time expires, the plugin just exits. No IP doesn't mean the build was unsuccessful...

Here's the function that uses that variable.

https://github.com/josenk/terraform-provider-esxi/blob/c60a4ae90a87601dee70301746a7bd4967b12430/esxi/guest_functions.go#L453

josenk commented 4 years ago

You're not the first that had similar issues with the guest startup time. So, I increased the default guest_startup_timeout to 120 seconds. It seems the old default (60 seconds) was a bit too short.

https://github.com/josenk/terraform-provider-esxi/releases/tag/v1.6.0