hashicorp/packer-plugin-vsphere

Packer vsphere-iso not detecting change in IP address after reboot Ubuntu 21.10 auto install

hc-github-team-packer opened this issue · 10 comments

This issue was originally opened by @NathanDotTo in hashicorp/packer#11385 and has been migrated to this repository. The original issue description is below.


Overview of the Issue

I appear to be seeing the same defect as in #8528.

I am auto installing Ubuntu 21.10 using Cloud Init. The initial boot gets an IP address, which is released, and then the second boot gets another IP address. Packer is stuck with the first IP address though.

==> vsphere-iso.dev_vm_server: Typing boot command...
==> vsphere-iso.dev_vm_server: Waiting for IP...
==> vsphere-iso.dev_vm_server: IP address: 10.122.244.252
==> vsphere-iso.dev_vm_server: Using SSH communicator to connect: 10.122.244.252
==> vsphere-iso.dev_vm_server: Waiting for SSH to become available...

But, the DHCP logs show that 10.122.244.252 was released, so the VM will get a different IP address after reboot.

Nov 5 09:39:13 xxx dhcpd: DHCPRELEASE of 10.122.244.252 from 00:50:56:89:57:1b (ubuntu-server) via ens192 (found)

The logic here is that the initial boot of the VM is running a SSH server, but before the ubuntu user is configured via Cloud Init, so the attempt to connect to the SSH server at the initial IP address during that initial stage will fail authentication.

Then the server reboots and applies the Cloud Init settings. After rebooting, the IP address differs, so there is an I/O connection issue as Packer is trying the original address.

Reproduction Steps

source "vsphere-iso" "dev_vm_server" {
  username            = var.vcenter_username
  password            = var.vcenter_password
  vcenter_server      = var.vcenter_server
  cluster             = var.vcenter_cluster
  datacenter          = var.vcenter_datacenter
  datastore           = var.vcenter_vm_datastore
  guest_os_type       = "ubuntu64Guest"
  insecure_connection = "true"
  iso_checksum        = "sha256:e84f546dfc6743f24e8b1e15db9cc2d2c698ec57d9adfb852971772d1ce692d4"
  iso_urls            = ["https://releases.ubuntu.com/21.10/ubuntu-21.10-live-server-amd64.iso"]
  http_directory      = "./http"

  vm_name             = "dev_vm"
  CPUs                = 2
  RAM                 = 2048
  RAM_reserve_all     = true
  boot_wait           = "3s"
  convert_to_template = false
  boot_command        = [
    "c",
    "linux /casper/vmlinuz \"ds=nocloud-net;seedfrom=http://{{.HTTPIP}}:{{.HTTPPort}}/\" autoinstall quiet --- ",
    "<enter><wait>",
    "initrd /casper/initrd<enter><wait>",
    "boot<enter>",
  ]
  network_adapters {
    network      = "xxx"
    network_card = "e1000"
    mac_address = "00:50:56:89:57:1b"
  }
  storage {
    disk_size             = 40960
    disk_thin_provisioned = true
  }

  ssh_username = "ubuntu"
  ssh_password = "ubuntu"
  ssh_timeout  = "60m"
  ssh_handshake_attempts = 60
}

build {
  sources = [
    "source.vsphere-iso.dev_vm_server"
  ]

...
}


Steps to reproduce this issue

### Packer version

1.7.8

### Simplified Packer Template

See above

### Operating system and Environment details

macOS 12.0.1

### Log Fragments and crash.log files

https://gist.github.com/NathanDotTo/cff4ce63cce2bb66230e3c7740aab09e

What's the content of the user-data @NathanDotTo?

Ryan

Have you tried using ens33 (not ens32) with e1000, or more preferably ens192 with vmxnet3?

Ryan

Take a look at the Ubuntu 2@.04 example from my repo: https://github.com/rainpole/packer-vsphere. I don't specify the network type and let it determine based on the nic type of vmxnet3. Works perfectly.

Ryan

Glad to hear it's working now!

Please be sure to close the issue once all is confirmed as good.

Ryan

I can't close this issue as I don't see a "Close Issue" button. Please feel free to close on my behalf.

@hc-github-team-packer, please close.

Ryan

Thanks for working through this issue @tenthirtyam. Closing as requested.

Happy to help!