I have/had an oddity related to DHCP during a Packer build with ubuntu-21.10-live-server-amd64.iso on vSphere. This is most likely a Packer issue, so see:
https://github.com/hashicorp/packer/issues/11385
I am using this boot command:
"c",
"linux /casper/vmlinuz \"ds=nocloud-net;seedfrom=http://{{.HTTPIP}}:{{.HTTPPort}}/\" autoinstall quiet --- ",
"<enter><wait>",
"initrd /casper/initrd<enter><wait>",
"boot<enter>"
When the server initially boots, it gets an address from DHCP, which is the address that Packer then thinks is the address. Of course, during the install the server reboots, applying the config from the user-data
. After rebooting, the server has a new IP address from DHCP, which is not the address that Packer thinks the server has.
In the user-data
I do set dhcp-identifier: mac
, but that does not help here as the first DHCP address is released, as it should be, so will not be reassigned.
In the end, I added a <wait300>
at the end of the boot_command
, so that 5 min goes by, whilst the VM installs the kernel and reboots. After that 5 min, Packer will carry on and get the IP address that will work, and all is good. This is clearly not the best thing to do, so there might be a Packer fix here too.