Packer waits forever while connecting with WinRM (vsphere-clone for Windows)

I am trying to clone a Windows Server 2019 VM Template in vSphere ESXi 7.0 using the “vsphere-clone” plugin. I am just cloning the existing VM and creating a new VM with different IP.

It just keeps waiting at the below forever.
“Waiting for WinRM to become available…”

Packer Build:
>> packer build -var-file packer-windows.pkrvars.hcl packer-windows2019.pkr.hcl output will be in this color.

==> Cloning VM…
==> Mounting ISO images…
==> Adding configuration parameters…
==> Customizing VM…
==> Power on VM…
==> Waiting for IP…
==> IP address: X.Y.Z.A
==> Using WinRM communicator to connect: X.Y.Z.A
==> Waiting for WinRM to become available…
(it just hangs here forever)

I also checked the winrm status and that service is enabled and listening. But, this doesn’t succeed after the cloned VM reboots with a new IP Address.

nc -z -w1 X.Y.Z.A 5985;echo $?
Connection to X.Y.Z.A port 5985 [tcp/wsman] succeeded!

I am not able to figure out the issue with winrm. Please advise.

packer-windows.pkrvars.hcl.txt (721 Bytes)
packer-windows2019.pkr.hcl.txt (3.7 KB)

Do you make sysprep or not while you try to clone your VM ?
Cause if you do sysprep (generalize) it will remove the drivers files from the VM until the next reboot, and so Packer gets hung forever because network adapter gets removed (so packer try to connect to something that can’t answer)

Also, be sure to keep your WIndows firewall off (for testing purpose only) and check if this one get enabled while VM is cloned.

Finally, still for testing purpose, while Packer get stucks on winRM to become available, try to connect to your VM using winRM with those 2 cmdlets where X.X.X.X is the VM IP address

enter-pssession X.X.X.X -Credential $credentials -Port 5985

enter-pssession X.X.X.X -Credential $credentials -Port 5986