Issues with "Waiting for IP" timeout using vsphere-iso

As part of an automated build process at my work, I am learning packer to utilize it in building the VM templates we clone from in vSphere. I’m starting out with building our Centos 7 template but am encountering a “Waiting for IP” timeout error. The goal is to use our existing Foreman infrastructure as part of this process. The template has a profile in Foreman. Once a month or so, we will automate a process to move the template to build mode, download the Full Boot ISO, build the VM, and then convert it to a template. This will reduce the time it takes to bring up a new VM since it will be updated with the latest patches. In testing this, it works up to a point. The packer tool builds the VM fine and it comes up fully on the network (utilizing DHCP for the IP) but eventually gets torn down when the Waiting for IP timeout occurs.

It is my understanding that packer utilizes the open-vm-tools to get the IP. vmtoolsd is fully up on the VM after being built and vSphere is able to grab the IP from the VM but packer is not. Am I missing something here?

The packer version is 1.7.4 and the ESXi version is 6.7.0.

Thanks in advance for any insight.

centos7template.pkr.hcl:

packer {
  required_plugins {
    vsphere = {
      version = ">= 0.0.1"
      source  = "github.com/hashicorp/vsphere"
    }
  }
}

variable "iso_name" {
  type       = string
  default    = "templatecentos7dev_20210817_2047.iso"
  description = "ISO to build from generated by Foreman"

}

variable "boot_string" {
  type        = string
  default     = "foreman_special ipv6.disable=1 nameserver=10.xxx.xx.xx<enter>"
  description = "Default boot string for ISO generated by Foreman"

}

variable "vcenter_name" {
  type = string
  default = "vsphereserver.local"
  description = "Default vsphere server"
}

source "vsphere-iso" "centos7" {
  boot_command = [ var.boot_string ]
  boot_wait = "25s"
  vcenter_server = var.vcenter_name
  datacenter = "DCNAME"
  datastore = "Templates_Unity_01"
  username = "USERNAME"
  password = "PASSWORD"
  insecure_connection = true
  CPUs = 1
  RAM = 4096
  vm_name = "templatecentos7dev"
  cluster = "LinuxDev"
  iso_checksum = "md5:404301682d5e382a6027c3314288ef67"
  iso_url = var.iso_name
  ssh_username = "root"
  ip_wait_timeout = "45m"
  network_adapters {
    network = "VLAN_Linux"
    network_card = "vmxnet3"
    mac_address = "00:50:56:AA:AA:AA"
  }
  storage {
      disk_size = 20000
      disk_thin_provisioned = true
  }

}

build {
  name = "centos7"
  sources = [
    "source.vsphere-iso.centos7",
  ]
}

Error message:

==> centos7.vsphere-iso.centos7: Adding configuration parameters…
==> centos7.vsphere-iso.centos7: Set boot order temporary…
==> centos7.vsphere-iso.centos7: Power on VM…
==> centos7.vsphere-iso.centos7: Waiting 25s for boot…
==> centos7.vsphere-iso.centos7: Typing boot command…
==> centos7.vsphere-iso.centos7: Waiting for IP…
==> centos7.vsphere-iso.centos7: Timeout waiting for IP.
==> centos7.vsphere-iso.centos7: Clear boot order…
==> centos7.vsphere-iso.centos7: Power off VM…
==> centos7.vsphere-iso.centos7: Destroying VM…
Build ‘centos7.vsphere-iso.centos7’ errored after 35 minutes 42 seconds: Timeout waiting for IP.

==> Wait completed after 35 minutes 42 seconds

==> Some builds didn’t complete successfully and had errors:
→ centos7.vsphere-iso.centos7: Timeout waiting for IP.

==> Builds finished but no artifacts were created.

The issue ended up being related to the open-vm-tools configuration. After much headache, I fixed the issue by adding the following section to /etc/vmware-tools/tools.conf:

[guestinfo]
primary-nics=ens*

1 Like

Hello, ndrolf
Is it ks when you added it to /etc/vmware-tools/tools.conf you mentioned? I think you did it after installing open-vm-tools from ks.

I am in the same situation and need your help.
thank you

I too am encountering the same issue. I do not know how to statically assign IP in pkr.hcl or user-data.

I’m assuming that you’re using HTTP-based kickstart. If so, it’s quite likely that the machine image does not have access back to the the Packer host.

Check out Packer Examples for VMware vSphere where the project has options to flip from HTTP to disk-based kickstart for the Linux distros. You might be able to use this project to advanced your learning of Packer with vSphere.

Ryan Johnson
Senior Staff Solutions Architect | Product Engineering @ VMware, Inc.

Thank you Ryan- I appreciate the response!

I think my issue was some incorrect syntax in my grub2 line in the prk.hcl file where I statically assigned IP/Netmask/Gateway.

oh, and I think installing vm-tools first in the kickstart also may have helped :man_shrugging: