Question

I'm trying to understand why putting the network options in the provider block of Vagrantfile doesn't work. For example, this seems to work:

config.vm.define "mymachine" do |vbox_config|
  vbox_config.vm.network :private_network, ip: "10.10.10.10"

  vbox_config.vm.provider :virtualbox do |vb|
    vb.ssh.forward_agent = true
  end
end

but this doesn't work (network is not accessible):

config.vm.define "mymachine" do |vbox_config|

  vbox_config.vm.provider :virtualbox do |vb|
    vb.ssh.forward_agent = true
    vb.vm.network :private_network, ip: "10.10.10.10"
  end
end

It seems like I would want to set the network options to be specific to a provider and structure the Vagrantfile like the latter. Any ideas why it's not working?

Was it helpful?

Solution

If you want to set non-provider specific configuration inside a provider block you have to use a different syntax:

config.vm.define "mymachine" do |vbox_config|

  vbox_config.vm.provider :virtualbox do |vb, override|
    override.ssh.forward_agent = true
    override.vm.network :private_network, ip: "10.10.10.10"
  end
end

Indeed, the first argument is for provider specific configuration (e.g. vb.customize), while the second is for overrides. Please see the documentation for more information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top