hashicorp / vagrant-vmware-desktop

Official provider for VMware desktop products: Fusion, Player, and Workstation.
Mozilla Public License 2.0
270 stars 40 forks source link

Vagrant confused between two virtual boxes with SSH | Mac OS Big Sur | VMWare Fusion #51

Open rushi47 opened 2 years ago

rushi47 commented 2 years ago

Debug output

rushi@Rushikeshs-MacBook-Air uvagrant % vagrant port
The forwarded ports for the machine are listed below. Please note that
these values may differ from values configured in the Vagrantfile if the
provider supports automatic port collision detection and resolution.

    22 (guest) => 2222 (host)
---
rushi@Rushikeshs-MacBook-Air uvagrant % pwd
/-------/uvagrant

---
rushi@Rushikeshs-MacBook-Air uvagrant % vagrant ssh
vagrant@127.0.0.1's password:
vagrant@build:~
rushi@Rushikeshs-MacBook-Air demoMachine % vagrant port
    22 (guest) => 2200 (host)
---
rushi@Rushikeshs-MacBook-Air demoMachine % pwd
/-----/demoMachine
---
rushi@Rushikeshs-MacBook-Air demoMachine % vagrant ssh
Last login: Fri Sep 23 17:29:08 2022 from 192.168.103.1
vagrant@build:~$

Expected behavior

I have two Boxes running in different directories uvagrant and demoMachine (as shown in the output), when both of my boxes are running vagrant confuses while doing ssh even if I run from their respective directories. If I ssh in uvagrant machine it will go to demomachine, above is the output in debug log.

Screen Shot 2022-09-23 at 1 30 09 PM

Normally it should go to their respective machines, even if I use the machine names it still goes into different machines.

Actual behavior

Whenever I am trying to ssh into machine located in uvagrant directory will ssh into Machine located in demoMachine. Looks like ssh runs in conflict.

Reproduction information

Vagrant version

rushi@Rushikeshs-MacBook-Air uvagrant % vagrant -v
Vagrant 2.3.0

Host operating system

rushi@Rushikeshs-MacBook-Air demoMachine % uname -a
Darwin Rushikeshs-MacBook-Air.local 20.6.0 Darwin Kernel Version 20.6.0: Tue Feb 22 21:10:42 PST 2022; root:xnu-7195.141.26~1/RELEASE_ARM64_T8101 arm64
rushi@Rushikeshs-MacBook-Air demoMachine % sw_vers
ProductName:    macOS
ProductVersion: 11.6.5
BuildVersion:   20G527
rushi@Rushikeshs-MacBook-Air demoMachine %

Guest operating system

Steps to reproduce

  1. Install vmware fusion on mac os big sure
  2. Get the above guest os and spin up two instance of this machine
  3. Try SSH into them

Vagrantfile

Machine-1

rushi@Rushikeshs-MacBook-Air demoMachine % cat Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "bytesguy/ubuntu-server-20.04-arm64"
  config.vm.box_version = "1.0.0"
  config.vm.hostname = "build"
  config.vm.define "buildServer"
  config.vm.provider :vmware_fusion do |v, o|
    v.gui = true
    v.memory = 4024
    v.cpus = 4
   end
  config.vm.synced_folder "/---/sharedFolder","/home/vagrant/shared"
end

Machine-2

rushi@Rushikeshs-MacBook-Air demoMachine % cat Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "bytesguy/ubuntu-server-20.04-arm64"
  config.vm.box_version = "1.0.0"
  config.vm.hostname = "build"
  config.vm.define "buildServer"
  config.vm.provider :vmware_fusion do |v, o|
    v.gui = true
    v.memory = 4024
    v.cpus = 4
   end
  config.vm.synced_folder "/---/sharedFolder","/home/vagrant/shared"
end

Port host op :

rushi@Rushikeshs-MacBook-Air uvagrant % sudo lsof -i -n -P | grep 2200
Password:
vagrant-v   642           root   16u  IPv6 0xd60f8eac0f43ea4f      0t0    TCP *:2200 (LISTEN)

rushi@Rushikeshs-MacBook-Air uvagrant % sudo lsof -i -n -P | grep 2222
vagrant-v   642           root    9u  IPv6 0xd60f8eac0f7696ef      0t0    TCP *:2222 (LISTEN)
rushi@Rushikeshs-MacBook-Air uvagrant %
soapy1 commented 2 years ago

Heya thanks for opening up an issue!

One way to change the current Vagrant context is to use the VAGRANT_CWD environment variables. When set it will execute a Vagrant command as if Vagrant was running in another folder. So please ensure that VAGRANT_CWD is not set.

However, it looks like Vagrant is ssh'ing into the correct machines. From the output of the vagrant port commands provided, it looks like both machines get their own distinct port forwards for ssh. The vagrant ssh command seems to execute successfully. From the output provided it's hard to tell if vagrant is ssh'ing into the right machine since both are host names are set to 'build' in the Vagrantfiles and both machines are using the same box. So, I tried to recreate the issue, but set different hostnames for the machines so it would be more obvious if Vagrant was ssh'ing into the correct machine. Here they are:

In folder ~/project/dbl-test/one

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/bionic64"
  config.vm.hostname = "build-one"
  config.vm.define "buildServer"
  config.vm.provider :vmware_fusion do |v, o|
    v.gui = true
    v.memory = 4024
    v.cpus = 4
   end
end

In folder ~/project/dbl-test/two

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/bionic64"
  config.vm.hostname = "build-two"
  config.vm.define "buildServer"
  config.vm.provider :vmware_fusion do |v, o|
    v.gui = true
    v.memory = 4024
    v.cpus = 4
   end
end

Then I can vagrant up and ssh into the machine: from ~/project/dbl-test/one

 % vagrant ssh
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-58-generic x86_64)
# ... excluded for brevity ...
vagrant@build-one:~$ 

from ~/project/dbl-test/two

 % vagrant ssh
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-58-generic x86_64)
# ... excluded for brevity ...
vagrant@build-two:~$ 

If this issue persists after checking for VAGRANT_CWD, could you please share a bit more debug info. In particular it would be helpful if you

  1. set the config.vm.hostname to different names (so that the guest you are ssh'ing to is more easily identified)
  2. provide the output from vagrant ssh in both folders
  3. provide the output from vagrant global-status

Thanks!

rushi47 commented 2 years ago

Hey @soapy1 Thanks for writing it out and sorry for late reply. I changed hostname already but still encountering the issue below are vagrant files for both the machines : One named build

rushi@Rushikeshs-MacBook-Air demoMachine % cat Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "bytesguy/ubuntu-server-20.04-arm64"
  config.vm.box_version = "1.0.0"
  config.vm.hostname = "build"
  config.vm.define "buildServer"
  config.vm.provider :vmware_fusion do |v, o|
    v.gui = true
    v.memory = 4024
    v.cpus = 4
   end
  config.vm.synced_folder "/-excluded-/LKP/sharedFolder","/home/vagrant/shared"
end

Other is main

rushi@Rushikeshs-MacBook-Air uvagrant % cat Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "bytesguy/ubuntu-server-20.04-arm64"
  config.vm.box_version = "1.0.0"
  config.vm.define "main"
  config.vm.provider :vmware_fusion do |v, o|
    v.gui = true
    v.memory = 4024
    v.cpus = 4
   end
  config.vm.synced_folder "sharedFolder","/home/vagrant/localshared"
  config.vm.synced_folder "/-excluded-/LKP/sharedFolder","/home/vagrant/shared"
end

Vagrant global status

rushi@Rushikeshs-MacBook-Air demoMachine % vagrant global-status
id       name        provider      state   directory
-----------------------------------------------------------------------------------------------
f0e25da  default     vmware_fusion running /-excluded-/LKP/uvagrant
5fcd8c3  buildServer vmware_fusion running /-excluded-/LKP/demoMachine
c0dcfe1  main        vmware_fusion running /-excluded-/LKP/uvagrant

The above shows information about all known Vagrant environments
on this machine. This data is cached and may not be completely
up-to-date (use "vagrant global-status --prune" to prune invalid
entries). To interact with any of the machines, you can go to that
directory and run Vagrant, or you can use the ID directly with
Vagrant commands from any directory. For example:
"vagrant destroy 1a2b3c4d"

Logs attached. ps: ssh seems to hang on terminal when it was run with debug command : vagrant ssh --debug &> demo_machine.log demo_machine.log main_machine.log

rushi47 commented 2 years ago

@chrisroberts Hey, feel free to remove label waiting-reply from this one. Thanks :)