Vagrant confused between two virtual boxes with SSH | Mac OS Big Sur | VMWare Fusion
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
[email protected]'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.
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
- Spin up two vagrant machine on Mac OS Big Sur v11.6.5 using VMware fusion
- Try ssh into them using port, name or simply using vagrant ssh and it will fail
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
- Ubuntu 20.04 box : bytesguy/ubuntu-server-20.04-arm64
- VMware Fusion Version : Player Version e.x.p (20191287)
- VM run Version : vmrun version 1.17.0 build-20191287
Steps to reproduce
- Install vmware fusion on mac os big sure
- Get the above guest os and spin up two instance of this machine
- 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 %
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
- set the
config.vm.hostnameto different names (so that the guest you are ssh'ing to is more easily identified) - provide the output from
vagrant sshin both folders - provide the output from vagrant
global-status
Thanks!
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
@chrisroberts Hey, feel free to remove label waiting-reply from this one.
Thanks :)