hashicorp / packer-plugin-vsphere

Packer plugin for VMware vSphere Builder
https://www.packer.io/docs/builders/vsphere
Mozilla Public License 2.0
94 stars 91 forks source link

vsphere-iso: IPv6 ip_wait_address breaks "Waiting for SSH to become available" due to "too many colons in address". #333

Closed pinjic closed 4 months ago

pinjic commented 9 months ago

Overview of the Issue

Whilst creating IPv6-only packer images, we ran into the following problems:

Might be the same problem as described in https://github.com/hashicorp/packer/issues/9360.

Reproduction Steps

Packer Version

Packer v1.9.4

Plugin Version and Builders

Plugin: packer-plugin-vsphere_v1.2.2_x5.0_linux_amd64

Builder: vsphere-iso

VMware vSphere Version

7.0.3

Guest Operating System

Both tested with Ubuntu 22.04 LTS and Ubuntu 20.04 LTS.

Simplified Packer Buildfile

Operating System and Environment Details

Packer was run from my Ubuntu 22.04 LTS desktop.

bandit145 commented 7 months ago

I ran into the same issue and I have a working "fix" (this could be fixed in packer itself, or elsewhere in the code then where I inserted it).

The issue is somewhere I assume in the packer code packer is plugging whatever IP string it gets into a function that attempts to parse the IP according to: https://www.rfc-editor.org/rfc/rfc2732 . The fix is to introduce [] around the IPv6 address at some step in the process.

https://github.com/bandit145/packer-plugin-vsphere/blob/3d97f937cd61cea4a4819d1f66a439ab9664e76d/builder/vsphere/common/step_wait_for_ip.go#L174

In this example I just do a naive check if a ":" is in the string and concatenate the required brackets around it; this results in a successful connection:

==> centos_stream9.vsphere-iso.image: IP address: [2605:90f4:0:53:250:56ff:fea5:571f] ==> centos_stream9.vsphere-iso.image: Using SSH communicator to connect: [2605:90f4:0:53:250:56ff:fea5:571f] 2024/02/01 12:14:04 packer-plugin-vsphere plugin: 2024/02/01 12:14:04 [INFO] Waiting for SSH, up to timeout: 5m0s ==> centos_stream9.vsphere-iso.image: Waiting for SSH to become available... 2024/02/01 12:14:04 packer-plugin-vsphere plugin: 2024/02/01 12:14:04 [INFO] Attempting SSH connection to [2605:90f4:0:53:250:56ff:fea5:571f]:22... 2024/02/01 12:14:04 packer-plugin-vsphere plugin: 2024/02/01 12:14:04 [DEBUG] reconnecting to TCP connection for SSH 2024/02/01 12:14:04 packer-plugin-vsphere plugin: 2024/02/01 12:14:04 [DEBUG] handshaking with SSH 2024/02/01 12:14:05 packer-plugin-vsphere plugin: 2024/02/01 12:14:05 [DEBUG] handshake complete! 2024/02/01 12:14:05 packer-plugin-vsphere plugin: 2024/02/01 12:14:05 [DEBUG] Opening new ssh session 2024/02/01 12:14:05 packer-plugin-vsphere plugin: 2024/02/01 12:14:05 [INFO] agent forwarding enabled ==> centos_stream9.vsphere-iso.image: Connected to SSH!

I believe (but have not tried) that this could also be fixed in this portion: https://github.com/hashicorp/packer-plugin-vsphere/blob/c76697aef7159648fd1ed343f74f0201ea5c29d7/builder/vsphere/driver/vm.go#L718 by adding some manner of check and then properly formatting the address string if an IPv6 address is detected.

If wanted I could make a PR for whichever option is preferred (even if it's "it should be handled in packer").

tenthirtyam commented 7 months ago

@nywilken and @lbajolet-hashicorp for comment. ☝🏻