Pergunta

In my Vagrantfile I have configs for Virtualbox and for VMware. As the VMware providers for Windows/Linux and Mac have different names (vmware_workstation, vmware_fusion), but use the same downloaded box, I find myself speifying the same config twice.

config.vm.provider "vmware_fusion" do |v, override|
    v.vmx["memsize"] = "1024"
    v.vmx["numvcpus"] = "1"
end

config.vm.provider "vmware_workstation" do |v, override|
    v.vmx["memsize"] = "1024"
    v.vmx["numvcpus"] = "1"
end

What is the syntax for allowing me to combine these two into a single block, something like:

config.vm.provider in ["vmware_fusion", "vmware_workstation"] do |v, override|
   v.vmx["memsize"] = "1024"
   v.vmx["numvcpus"] = "1"
end

Many Thanks.

Foi útil?

Solução

This should work:

["vmware_fusion", "vmware_workstation"].each do |vmware_provider|
  config.vm.provider vmware_provider do |v, override|
    v.vmx["memsize"] = "1024"
    v.vmx["numvcpus"] = "1"
  end
end

Outras dicas

Looks like you are restricted to one provider per machine (bottom of the page), though in a multimachine environment you can specify a provider per machine

So maybe you could do something like

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

  machines = [
    { name: "machine1_fusion", provider: "vmware_fusion" },
    { name: "machine1_workstation", provider: "vmware_workstation" }
  ]

  machines.each do |machine|
    config.vm.define machine[:name] do |m|
      ... #box config etc
      m.vm.provider machine[:provider] do |p|
        p.vmx["memsize"] = "1024"
        p.vmx["numvcpus"] = "1"
      end
    end
  end
end
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top