frapposelli / vagrant-vcenter

A Vagrant provider for VMware vCenter®
MIT License
106 stars 36 forks source link

Plugin needs to cache good addreses #47

Closed jkugler closed 3 years ago

jkugler commented 5 years ago

I have a very odd case. I'm using vagrant with vCenter, and using rsync folders. Most of the time it works, but some times the VM will boot, properly report its IPv4 address, swap out the ssh keys, but when it goes to connect for the rsync, it tries to use the VM's link-local address, and fails. Like so (please forgive the Jenkins copy/paste)

-----> Starting Kitchen (v1.23.2)
-----> Cleaning up any prior instances of <source-rhel-6-bento>
-----> Destroying <source-rhel-6-bento>...
       Finished destroying <source-rhel-6-bento> (0m0.00s).
-----> Testing <source-rhel-6-bento>
-----> Creating <source-rhel-6-bento>...
       Bringing machine 'default' up with 'vsphere' provider...
       ==> default: Calling vSphere CloneVM with the following settings:
       ==> default:  -- Template VM: DC1/vm/CICD/bento-rhel-6.10-x86_64-LATEST
       ==> default:  -- Target VM: DC1/vm/CICD/source-rhel-6-bento-jnprcfg-lynis-1545253719-50
       ==> default: New virtual machine successfully cloned
       ==> default: Waiting for the machine to report its IP address...
           default: Timeout: 240 seconds
           default: IP: 10.199.251.38
       ==> default: Waiting for machine to boot. This may take a few minutes...
           default: SSH address: 10.199.251.38:22
           default: SSH username: vagrant
           default: SSH auth method: private key
           default: 
           default: Vagrant insecure key detected. Vagrant will automatically replace
           default: this with a newly generated keypair for better security.
           default: 
           default: Inserting generated public key within guest...
           default: Removing insecure key from the guest if it's present...
           default: Key inserted! Disconnecting and reconnecting using new SSH key...
       ==> default: Machine booted and ready!
       ==> default: Setting hostname...
       ==> default: Installing rsync to the VM...
       ==> default: Rsyncing folder: /var/lib/jenkins/workspace/MergeRequests/project/Distribution/rhel-6/Image/bento/ => /test_local_files/juniper/jnprcfg-lynis
       There was an error when attempting to rsync a synced folder.
       Please inspect the error message below for more info.

       Host path: /var/lib/jenkins/workspace/MergeRequests/jnprcfg-lynis/Distribution/rhel-6/Image/bento/
       Guest path: /test_local_files/company/project
       Command: "rsync" "--verbose" "--archive" "--delete" "-z" "--copy-links" "--no-owner" "--no-group" "--rsync-path" "sudo rsync" "-e" "ssh -p 22 -o LogLevel=FATAL  -o ControlMaster=auto -o ControlPath=/tmp/ssh.413 -o ControlPersist=10m  -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i '/var/lib/jenkins/workspace/MergeRequests/project/Distribution/rhel-6/Image/bento/.kitchen/kitchen-vagrant/source-rhel-6-bento/.vagrant/machines/default/vsphere/private_key'" "--exclude" ".vagrant/" "/var/lib/jenkins/workspace/MergeRequests/project/Distribution/rhel-6/Image/bento/" "vagrant@[fe80::250:56ff:fe97:154c]:/test_local_files/company/project"
       Error: rsync: connection unexpectedly closed (0 bytes received so far) [sender]
       rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.2]<�/pre>

It had the "good" IPv4 address, and it worked. Then it got the IPv6 link-local address from somewhere, which did not work. Can we cache the first-reported address? Or ignore link-local addresses, and ask again? I guess some environments do use link local addresses, so discarding may not be the best course of action. But caching the address first acquired seems like a sane thing to do.

jkugler commented 5 years ago

Seems like caching https://github.com/frapposelli/vagrant-vcenter/blob/master/lib/vagrant-vcenter/action/read_ssh_info.rb#L29 or here https://github.com/frapposelli/vagrant-vcenter/blob/master/lib/vagrant-vcenter/provider.rb#L19 would be a good course of action.

jkugler commented 5 years ago

Oh, snap. I'm using vagrant-vsphere, not vagrant-center. Siiiigh. Sorry for the noise.