Waiting for SSH to become available

I’ve been trying to create an image using packer-plugin-qemu and I consistently have failed results.

I am probably missing something obvious related to network.
This issue is quite common, just search for “Waiting for SSH to become available…”, it is the standard step which a build process hangs.

I am on a macos host.
I’ve tried it on ubuntu as docker container. same issue.
It hangs forever on Waiting for SSH to become available…

Does anyone has any tip on how to debug this ?

Here are some logs
==> qemu.batman: Creating floppy disk…
2022/05/06 11:19:45 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: 2022/05/06 11:19:45 Floppy path: /tmp/packer4188394388
2022/05/06 11:19:45 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: 2022/05/06 11:19:45 Initializing block device backed by temporary file
2022/05/06 11:19:45 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: 2022/05/06 11:19:45 Formatting the block device with a FAT filesystem…
2022/05/06 11:19:45 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: 2022/05/06 11:19:45 Initializing FAT filesystem on block device
2022/05/06 11:19:45 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: 2022/05/06 11:19:45 Reading the root directory from the filesystem

==> qemu.batman: Found port for communicator (SSH, WinRM, etc): 3170.
==> qemu.batman: Looking for available port between 5900 and 6000 on 127.0.0.1
2022/05/06 11:19:45 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: 2022/05/06 11:19:45 Looking for available port between 5900 and 6000 on 127.0.0.1
2022/05/06 11:19:45 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: 2022/05/06 11:19:45 Found available port: 5947 on IP: 127.0.0.1
2022/05/06 11:19:45 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: 2022/05/06 11:19:45 Found available VNC port: 5947 on IP: 127.0.0.1
2022/05/06 11:19:45 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: 2022/05/06 11:19:45 Qemu --version output: QEMU emulator version 4.2.1 (Debian 1:4.2-3ubuntu6.21)
2022/05/06 11:19:45 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: Copyright (c) 2003-2019 Fabrice Bellard and the QEMU Project developers
2022/05/06 11:19:45 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: 2022/05/06 11:19:45 Qemu version: 4.2.1

==> qemu.batman: Starting VM, booting from CD-ROM
qemu.batman: view the screen of the VM, connect via VNC without a password to
qemu.batman: vnc://127.0.0.1:5947
qemu.batman: The VM will be run headless, without a GUI. If you want to
qemu.batman: view the screen of the VM, connect via VNC without a password to
qemu.batman: vnc://127.0.0.1:5947

==> qemu.batman: Waiting 1m0s for boot…
==> qemu.batman: Connecting to VM via VNC (127.0.0.1:5947)
2022/05/06 11:20:47 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: 2022/05/06 11:20:47 Connected to VNC desktop: QEMU (ubuntu20-batman)
qemu.batman: Not using a NetBridge – skipping StepWaitGuestAddress
==> qemu.batman: Using SSH communicator to connect: 127.0.0.1
2022/05/06 11:21:22 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: 2022/05/06 11:21:22 [INFO] Waiting for SSH, up to timeout: 20m0s
==> qemu.batman: Waiting for SSH to become available…
2022/05/06 11:21:22 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: 2022/05/06 11:21:22 [INFO] Attempting SSH connection to 127.0.0.1:3170…
2022/05/06 11:21:22 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: 2022/05/06 11:21:22 [DEBUG] reconnecting to TCP connection for SSH
2022/05/06 11:21:22 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: 2022/05/06 11:21:22 [DEBUG] handshaking with SSH
2022/05/06 11:22:22 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: 2022/05/06 11:22:22 [DEBUG] SSH handshake err: Timeout during SSH handshake
2022/05/06 11:22:29 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: 2022/05/06 11:22:29 [INFO] Attempting SSH connection to 127.0.0.1:3170…
2022/05/06 11:22:29 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: 2022/05/06 11:22:29 [DEBUG] reconnecting to TCP connection for SSH
2022/05/06 11:22:29 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: 2022/05/06 11:22:29 [DEBUG] handshaking with SSH
2022/05/06 11:23:29 packer-plugin-qemu_v1.0.3_x5.0_linux_amd64 plugin: 2022/05/06 11:23:29 [DEBUG] SSH handshake err: Timeout during SSH handshake

packer {
  required_plugins {
    qemu = {
      version = ">= 1.0.3"
      source  = "github.com/hashicorp/qemu"
    }
  }
}

build {
  name    = "qemu.batman"
  sources = ["source.qemu.batman"]
}

source "qemu" "batman" {
  boot_command = [
    "<esc><wait>",
    "<esc><wait>",
    "<enter><wait>",
    "/install/vmlinuz ",
    "initrd=/install/initrd.gz ",
    "net.ifnames=0 ",
    "auto-install/enable=true ",
    "debconf/priority=critical ",
    "preseed/url=http://{{.HTTPIP}}:{{.HTTPPort}}/preseed.cfg ",
    "<enter>"
  ]
  disk_size           = "10G"
  floppy_files        = ["preseed.cfg"]
  iso_url             = "http://releases.ubuntu.com/20.04/ubuntu-20.04.4-live-server-amd64.iso"
  iso_checksum        = "sha256:28ccdb56450e643bad03bb7bcf7507ce3d8d90e8bf09e38f6bd9ac298a98eaad"
  output_directory    = "output-ubuntu20-batman"
  shutdown_command    = "echo 'packer' | sudo -S shutdown -P now"
  format              = "qcow2"
  ssh_username        = "root"
  ssh_password        = "root"
  ssh_timeout         = "20m"
  vm_name             = "ubuntu20"
  net_device          = "virtio-net"
  disk_interface      = "virtio"
  boot_wait           = "60s"
  use_default_display = true
  headless            = true