Automatically selecting a provider

92 views
Skip to first unread message

Lucius Bono

unread,
Aug 13, 2015, 12:29:54 PM8/13/15
to Vagrant
Having trouble creating a Vagrantfile that will automatically select an available provider / box pair. Here is my Vagrantfile so far: 

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.require_version ">= 1.6.2"

Vagrant.configure("2") do |config|
    config.vm.box = "windows_81"
    config.vm.communicator = "winrm"

    config.vm.guest = :windows

    config.vm.network :forwarded_port, guest: 3389, host: 3389, id: "rdp", auto_correct: true
    config.vm.network :forwarded_port, guest: 5985, host: 5985, id: "winrm", auto_correct: true

    config.vm.provider "vmware_fusion" do |v, override|
        v.vmx["memsize"] = "2048"
        v.vmx["numvcpus"] = "2"
        v.vmx["ethernet0.virtualDev"] = "vmxnet3"
        v.vmx["scsi0.virtualDev"] = "lsisas1068"
    end

    config.vm.provider "vmware_workstation" do |v, override|
        v.vmx["memsize"] = "2048"
        v.vmx["numvcpus"] = "2"
        v.vmx["ethernet0.virtualDev"] = "vmxnet3"
        v.vmx["scsi0.virtualDev"] = "lsisas1068"
    end

    config.vm.provider "virtualbox" do |v, override|
        v.customize ["modifyvm", :id, "--memory", 2048]
        v.customize ["modifyvm", :id, "--cpus", 2]
        v.customize ["setextradata", "global", "GUI/SuppressMessages", "all" ]
    end

end

I have both Virtualbox and VMWare Fusion (with the VMWare Fusion Vagrant plugin, of course) installed on this system. If the VMWare Fusion box is installed, no problem - the Vagrantfile fires up right away - however, if I only install a Virtualbox box with the name "windows_81" I have to specify the provider in vagrant up or else I get an error. 

This isn't a big deal, but from what I understand Vagrant should be able to navigate this scenario automatically - which leads me to believe that my Vagrantfile is written incorrectly. This Vagrantfile is mostly cannibalized from other projects, I am not super comfortable with writing my own Vagrantfiles yet. 

Any help would be appreciated! The last piece of this is I am running Vagrant 1.7.2 due to an issue I'm having with 1.7.4 (which I will log an issue in Github for as soon as I get a moment). 

dragon788

unread,
Aug 14, 2015, 11:08:42 AM8/14/15
to Vagrant
Lucius, in order for Vagrant to automatically select a provider, you would need to supply it a metadata.json file that tells it which providers are available for the box, and this is usually done at the time the box is created (in Atlas for example). If you have two boxes with the same name locally, you WILL always have to specify the provider for one, though you can change which provider is used by default by setting an environment variable with your preferred provider.

If you have more questions let us know, I think there have been examples of the dual provider metadata file posted in the past, otherwise I have one we use regularly for our boxes, but we have switched from Vbox to VMware and no longer do the dual provider thing.
Reply all
Reply to author
Forward
0 new messages