hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.33k stars 4.44k forks source link

Vagrant defaults to VMWare if the VMWare plugin is installed #4654

Closed uchagani closed 7 years ago

uchagani commented 10 years ago

Boxes were created for virtualbox and the vagrant file configures for virtualbox but because I have the vmware_workstation plugin installed, it always defaults to that.

I would think that if metadata.json specifies virtualbox and the vagrant file configures for virtualbox i shouldn't have to force vagrant up with the --provider flag.

sethvargo commented 10 years ago

@uchagani what metadata.json are you referring to? Could you please post your Vagrantfile as well? What version of Vagrant (vagrant -v)?

uchagani commented 10 years ago

The metadata.json that vagrant package adds when you package a base box. For my two boxes that I created metadata.json says: {"provider":"virtualbox"}

After I installed the vmware plugin, I started noticing the behavior above.

Base Box Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.communicator = "winrm"  
  config.vm.box = "base"
  config.vm.synced_folder '.', '/vagrant', disabled: true
  config.vm.network "forwarded_port", host: 3389, guest: 3389, auto_correct: true 
  config.vm.network "public_network", id: "p-network", bridge: "Broadcom BCM5709C NetXtreme II GigE (NDIS VBD Client) #60"
  end 
end

Vagrantfile:

Vagrant.configure("2") do |config|

  config.vm.define "controller" do |controller|
    controller.vm.provider "virtualbox" do |vb|
      vb.name = controller.vm.hostname
    end
  end

  config.vm.define "client" do |client|
    client.vm.provider "virtualbox" do |vb|   
      vb.name = client.vm.hostname    
    end
  end  
end
sethvargo commented 10 years ago

Thank you @uchagani. I will try to get a reproduction case.

mitchellh commented 10 years ago

This is correct. Vagrant core chooses a provider before it reads the box. Available boxes is not taken into account in choosing the box. This sounds like a decent feature request, though.

uchagani commented 10 years ago

Is it possible for vagrant to see what box the user is spinning up and choose that provider?

For example, if I have both VirtualBox and VMWare boxes registered in vagrant, but my vagrant file is referencing the VirtualBox boxes, then virtual box provider is used.

mitchellh commented 10 years ago

@uchagani Not in the current flow of things.

mitchellh commented 10 years ago

Technically, of course, but it would require a bit of a rearchitecture of how Vagrant works internally.

milosgajdos commented 9 years ago

I'm seeing possibly the same problem. I have the following Vagrantfiles.

When I try to bring up both containers via vagrant up I get:

An error occurred while executing multiple actions in parallel.
Any errors that occurred are shown below.

An error occurred while executing the action on the 'socat'
machine. Please handle this error then try again:

The box you're attempting to add doesn't support the provider
you requested. Please find an alternate box or use an alternate
provider. Double-check your requested provider to verify you didn't
simply misspell it.

If you're adding a box from HashiCorp's Atlas, make sure the box is
released.

Name: ubuntu/trusty64
Address: https://atlas.hashicorp.com/ubuntu/trusty64
Requested provider: ["vmware_desktop", "vmware_fusion", "vmware_workstation"]

An error occurred while executing the action on the 'pv'
machine. Please handle this error then try again:

The box you're attempting to add doesn't support the provider
you requested. Please find an alternate box or use an alternate
provider. Double-check your requested provider to verify you didn't
simply misspell it.

If you're adding a box from HashiCorp's Atlas, make sure the box is
released.

Name: ubuntu/trusty64
Address: https://atlas.hashicorp.com/ubuntu/trusty64
Requested provider: ["vmware_desktop", "vmware_fusion", "vmware_workstation"]

The strangest thing is that when I try to bring up the machine using the Vagrantfile referred to in d.vagrant_vagrantfile on its own I get similar error:

Bringing machine 'dockerhost' up with 'vmware_fusion' provider...
==> dockerhost: Box 'ubuntu/trusty64' could not be found. Attempting to find and install...
    dockerhost: Box Provider: vmware_desktop, vmware_fusion, vmware_workstation
    dockerhost: Box Version: >= 0
==> dockerhost: Loading metadata for box 'ubuntu/trusty64'
    dockerhost: URL: https://atlas.hashicorp.com/ubuntu/trusty64
The box you're attempting to add doesn't support the provider
you requested. Please find an alternate box or use an alternate
provider. Double-check your requested provider to verify you didn't
simply misspell it.

If you're adding a box from HashiCorp's Atlas, make sure the box is
released.

Name: ubuntu/trusty64
Address: https://atlas.hashicorp.com/ubuntu/trusty64
Requested provider: ["vmware_desktop", "vmware_fusion", "vmware_workstation"]

Basically, looks like when you have installed vmware fusion plugin you are doomed :-)

xacaxulu commented 9 years ago

+1

xacaxulu commented 9 years ago

@uchagani did you figure out a workaround for this?

uchagani commented 9 years ago

@xacaxulu you can provide the --provider flag to force a specific provider.

ryanchapman commented 9 years ago

@milosgajdos83, I just ran into the same thing as you... was trying to move from VirtualBox to VMware Fusion, and had the following Vagrantfile:

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    config.vm.define "development", autostart: false do |dev|
        dev.vm.box = "ubuntu/precise64"
        dev.vm.provider "vmware_fusion" do |v|
            v.memory = 512
        end

        dev.vm.provision "ansible" do |ansible|
            ansible.playbook = "vagrant-provision.yml"
        end
    end
end

Attempting to up the development machine gives:

$ vagrant up development
Bringing machine 'development' up with 'vmware_fusion' provider...
==> development: Box 'ubuntu/precise64' could not be found. Attempting to find and install...
    development: Box Provider: vmware_desktop, vmware_fusion, vmware_workstation
    development: Box Version: >= 0
==> development: Loading metadata for box 'ubuntu/precise64'
    development: URL: https://atlas.hashicorp.com/ubuntu/precise64
The box you're attempting to add doesn't support the provider
you requested. Please find an alternate box or use an alternate
provider. Double-check your requested provider to verify you didn't
simply misspell it.

If you're adding a box from HashiCorp's Atlas, make sure the box is
released.

Name: ubuntu/precise64
Address: https://atlas.hashicorp.com/ubuntu/precise64
Requested provider: ["vmware_desktop", "vmware_fusion", "vmware_workstation"]

Looking at the atlas site (https://vagrantcloud.com/ubuntu/boxes/precise64), I see that ubuntu/precise64 does not support the vmware_fusion provider. Using hashicorp/precise64 (https://vagrantcloud.com/hashicorp/boxes/precise64) instead does work. So I changed the Vagrantfile to:

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    config.vm.define "development", autostart: false do |dev|
        dev.vm.box = "hashicorp/precise64"
        dev.vm.provider "vmware_fusion" do |v|
            v.memory = 512
        end

        dev.vm.provision "ansible" do |ansible|
            ansible.playbook = "vagrant-provision.yml"
        end
    end
end

Now vagrant up development works:

$ vagrant up development
Bringing machine 'development' up with 'vmware_fusion' provider...
==> development: Box 'hashicorp/precise64' could not be found. Attempting to find and install...
    development: Box Provider: vmware_desktop, vmware_fusion, vmware_workstation
    development: Box Version: >= 0
==> development: Loading metadata for box 'hashicorp/precise64'
    development: URL: https://atlas.hashicorp.com/hashicorp/precise64
==> development: Adding box 'hashicorp/precise64' (v1.1.0) for provider: vmware_fusion
    development: Downloading: https://vagrantcloud.com/hashicorp/boxes/precise64/versions/1.1.0/providers/vmware_fusion.box
==> development: Successfully added box 'hashicorp/precise64' (v1.1.0) for 'vmware_fusion'!
==> development: Cloning VMware VM: 'hashicorp/precise64'. This can take some time...
==> development: Checking if box 'hashicorp/precise64' is up to date...
==> development: Verifying vmnet devices are healthy...
==> development: Preparing network adapters...
==> development: Starting the VMware VM...
==> development: Waiting for machine to boot. This may take a few minutes...
    development: SSH address: XX.XX.XX.XX:22
    development: SSH username: XXXX
    development: SSH auth method: private key
    development:
    development: Vagrant insecure key detected. Vagrant will automatically replace
    development: this with a newly generated keypair for better security.
    development:
    development: Inserting generated public key within guest...
    development: Removing insecure key from the guest if its present...
    development: Key inserted! Disconnecting and reconnecting using new SSH key...
==> development: Machine booted and ready!
==> development: Forwarding ports...
    development: -- 22 => 2222
==> development: Configuring network adapters within the VM...
==> development: Waiting for HGFS kernel module to load...
==> development: Enabling and configuring shared folders...
    development: -- /Users/XXXXX/XXXX/XXXXX: /vagrant
==> development: Running provisioner: ansible...

Certainly not related to the original post, but thought it might help others...

fiorix commented 9 years ago

Yeah that works but we want trusty, not precise. I'm already regretting the vmware plugin, it's pretty much useless since most boxes are for the default vbox provider.

chasrmartin commented 8 years ago

I'm having similar problems. now that I've installed the vmware provider, vagrant always wants to use vmware unless I use the --provider flag explicitly.

It'd be nice to be able to set a default provider so I do'nt go through a lot of false starts.

stackedsax commented 8 years ago

@chasrmartin you can set a default provider. Just add this to your .bashrc or whatever:

export VAGRANT_DEFAULT_PROVIDER=virtualbox # chooses virtualbox as the default provider

Hope that helps.

ijstokes commented 8 years ago

I have solved this problem either with

export VAGRANT_DEFAULT_PROVIDER=virtualbox

environment variable or by using the CLI flag:

vagrant up --provider virtualbox

however it is very surprising to me that my Vagrantfile setting is not sufficient:

  config.vm.provider "virtualbox"

Can anyone comment?

chasrmartin commented 8 years ago

I had some success with this code fragment:

Vagrant.configure(2) do |config|

Prefer virtualbox,

see https://docs.vagrantup.com/v2/providers/basic_usage.html

config.vm.provider "virtualbox" do |v| v.gui = true end

Not tested with VMWare yet. VMWare requires a vagrant plugin.

config.vm.provider "vmware_fusion" do |v| v.gui = true end

but didn't explore it further because I wasn't happy with Vmware anyway so uninstalled the plugin.

On Thu, Jan 21, 2016 at 4:20 PM, Ian Stokes-Rees notifications@github.com wrote:

I have solved this problem either with

export VAGRANT_DEFAULT_PROVIDER=virtualbox

environment variable or by using the CLI flag:

vagrant up --provider virtualbox

however it is very surprising to me that my Vagrantfile setting is not sufficient:

config.vm.provider "virtualbox"

Can anyone comment?

— Reply to this email directly or view it on GitHub https://github.com/mitchellh/vagrant/issues/4654#issuecomment-173747041.

jloomb commented 8 years ago

+1 I (guessing it wasnt intentional) used to be able to vagrant up without --provider=*. I have a complex multi machine/provider Vagrantfile which was using the defined provider?? Sorry cant recall which version I was on at the time.

jtreminio commented 8 years ago

If anyone has any trouble with this, add the following to the top of your Vagrantfile:

ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox'

chrisroberts commented 8 years ago

This should be fixed now via #7756. Please let me know if you are still experiencing this issue. Thanks!

gildegoma commented 8 years ago

@chrisroberts I have verified (with Vagrant 1.8.7 and vagrant-vmware-fusion 4.0.14). The issue is still present: By default, the VMware provider is automatically selected (even if the base box does not support it).

chrisroberts commented 8 years ago

@gildegoma Okay, thanks for the confirmation! I'll have a look today and see if it's something that can be easily fixed up.

chrisroberts commented 8 years ago

After getting this reproduced locally, it is "partially" fixed based on expectations described within this issue. #7756 fixed the provider selection when "hinted" by the Vagrantfile. This means that:

Vagrant.configure(2) do |config|
  config.vm.box = 'hashicorp/precise64'
end

will result in a provider of vmware. If we hint the provider:

Vagrant.configure(2) do |config|
  config.vm.box = 'hashicorp/precise64'
  config.vm.provider :virtualbox 
end

this will result in virtualbox as the provider. This still doesn't help for a box that doesn't support the selected provider, so I'm digging into that.

chrisroberts commented 7 years ago

The modifications required for doing detection on the box metadata to choose a supported provider is much more intensive than the benefit gained. If anyone wants to provide a PR for it, I will be happy to help with reviews and guidance. At this point, however, the changes required are too drastic for a small gain where setting the provider explicitly via CLI flag or defaulting it via env var is easy enough. Cheers!

martinandersson commented 6 years ago

I wouldn't call this one a "small gain". I think it is the opposite, to be honest. I am dumbfounded every time I run into this issue. I have a VirtualBox box, but Vagrant crash and whines on up and says he can't start the box with VMware. I'm like, "yeah, who the f### asked you too?" Really, it's like putting in the first gear in the car and when you hit the gas pedal the car reverses.

The fact that the box itself is not taken into account when selecting which provider to run with is a bit of a handicap which I think we can all agree too. I totally understand that sometimes what appears like a small change can require lots of work and big architectural changes. But why close the issue as if it has gone away? This is a real handicap for Vagrant, a sort of "laughable" one if you ask me. We should at least leave it open and let it gain some attraction. And I think that even without a PR from the outside, Hashicorp should want to fix this issue sooner or later.

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.