2
I packaged a VirtualBox with all the settings I wanted. I set network to 'bridged adapter' (Vagrant calls it 'public_network'). I even looked at box.ovf
in the .box
file and it said
$ tar xOf nycmesh-qmp-openwrt.box box.ovf | less
<NetworkSection>
<Info>Logical networks used in the package</Info>
<Network ovf:name="Bridged">
<Description>Logical network used by this appliance.</Description>
But when I tried to add the box with vagrant box add box-name box.box
, and init
the box, then it generated the machine without a bridged adapter. It used NAT.
I even updated the .box
file (which is a gzipped tar file) and overwrote the Vagrantfile
with my custom Vagrantfile
which had
config.vm.network "public_network"
I re-added the box (with --force
), ran vagrant init box-name
again, and it still generated a Vagrantfile
with config.vm.network
commented out!
So, how?
Vagrant 2.0.1
This is my manually created VM network in VirtualBox:
I created package-the-vagrantfile/Vagrantfile
containing
Vagrant.configure("2") do |config|
config.vm.network "public_network"
config.vm.provider "virtualbox" do |vb|
vb.memory = "64"
end
end
According to the documentation
https://www.vagrantup.com/docs/networking/public_network.html
I package this VM with
$ vagrant package --base node --vagrantfile package-the-vagrantfile/Vagrantfile
It creates package.box
. I instantiate the box with
$ vagrant init package.box --minimal ; vagrant up
It starts up a new box...
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'package.box'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: node_default_1522176655197_96615
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
But it has the wrong network
It does have the correct memory
The network directive is in the box too.
$ tar -xOf package.box ./include/_Vagrantfile
Vagrant.configure("2") do |config|
config.vm.network "public_network"
...
$ tar -xOf package.box ./Vagrantfile
Vagrant::Config.run do |config|
...
# Load include vagrant file if it exists after the auto-generated
# so it can override any of the settings
include_vagrantfile = File.expand_path("../include/_Vagrantfile", __FILE__)
load include_vagrantfile if File.exist?(include_vagrantfile)