Packer connecting to Ubuntu "too early", how to enforce a delay?

Making an Ubuntu 20.04 template using the vsphere-iso builder, and Packer v1.7.7, I’m seeing a problem where the provisioner starts attempting to connect to the VM way too early, basically as soon as the VM starts reporting the ip address obtained via DHCP to VSphere, this happens roughly 3min into the process. This results in repeatedly failing ssh login attempts:

2021/10/24 20:50:31 packer-builder-vsphere-iso plugin: [DEBUG] Detected authentication error. Increasing handshake attempts.
2021/10/24 20:50:38 packer-builder-vsphere-iso plugin: [INFO] Attempting SSH connection to my.ip.address.here:22…
2021/10/24 20:50:38 packer-builder-vsphere-iso plugin: [DEBUG] reconnecting to TCP connection for SSH
2021/10/24 20:50:38 packer-builder-vsphere-iso plugin: [DEBUG] handshaking with SSH
2021/10/24 20:50:41 packer-builder-vsphere-iso plugin: [DEBUG] SSH handshake err: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none password], no supported methods remain

And Packer gives up on the entire thing way before the installation process is finished and the machine is rebooted with the install finished, SSH enabled and packer user present. It looks as if “pause_before_connecting” is not a solution, as according to documentation and various dev comments, it only pauses provisioners, not actual connection attempts, which would still continue and eventually cause failure.

I haven’t had this issue with Redhat-family of distributions as seemingly they don’t immideately start reporting their ip to vsphere, but only after I separately install and start the vmtoolsd service. But Ubuntu behaves differently here, reporting the obtained up upwards very quickly, resulting in a build failure. How can I force Packer to not attempt any SSH connections during the first boot of the build or force in a delay?

Worked around this issue using:

early-commands:

  • systemctl stop ssh

In my user-data for subiquity installer. Now I need to figure out how to make Packer pick up the new dhcp-obtained ip address, which changed happened after the first reboot. And also how to have subiquity not throw a total fit if the installation attempts installing multiple services with some of them failing to immideately launch (the idea is to clean-up irrelevant hypervisor services via ansible post-install).

1 Like

I have the same issue. Did you resolved it?

I had the same problem building Ubuntu 20.04. I used the following settings to fix it.

ssh_timeout = "30m"
ssh_handshake_attempts = 1000

That allowed enough time for the VM to be built and reboot so Packer could shut it down properly.

2 Likes

This doesn’t work in my case, because the ssh service starts running while the installation process is still running, so packer gets an authentication failed response and it takes that as a proper answer and fails. Rather frustrating.

I saw your answer later. Stopping ssh with early-commands actually worked for me. I appreciate it!