I used packer to create a vagrant box for a workshop I am running, and packaged vagrantfile in the box via the vagrantfile_template
directive in the Vagrant post-processor as shown:
...
"post-processors": [{
"type": "vagrant",
"vagrantfile_template": "vagrantfile_templates/workshop",
"compression_level": "{{user `compression_level`}}",
"output": "fedora-22-x86_64.box"
}],
...
The contents of the resulting .box
are:
% tar -tf workshop.box
Vagrantfile
box.ovf
metadata.json
packer-fedora-22-x86_64-disk1.vmdk
The contents of Vagrantfile
in the box seem OK, and include the contents of the vagrantfile_template
specified in the packer configuration. Note that this Vagrantfile
defines two VMs named client
and server
:
% tar -O -xf freeipa-workshop.box Vagrantfile
# The contents below were provided by the Packer Vagrant post-processor
Vagrant.configure("2") do |config|
config.vm.base_mac = "0800278AF3E8"
end
# The contents below (if any) are custom contents provided by the
# Packer template during image build.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "workshop"
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.define "server" do |server|
server.vm.network "private_network", ip: "192.168.33.10"
server.vm.hostname = "server.ipademo.local"
end
config.vm.define "client" do |client|
client.vm.network "private_network", ip: "192.168.33.20"
client.vm.hostname = "client.ipademo.local"
end
end
I added the box to vagrant with the name workshop
:
% vagrant box add --name workshop workshop.box
==> box: Adding box 'workshop' (v0) for provider:
box: Downloading: file:///.../workshop.box
==> box: Successfully added box 'workshop' (v0) for 'virtualbox'!
% vagrant box list
workshop (virtualbox, 0)
Problem description
When I execute vagrant init workshop
and then vagrant up
, the Vagrantfile
included in the box is not applied:
% vagrant init workshop
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
% cat Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "workshop"
... and so on (the rest of the default Vagrantfile)
% vagrant up --provider virtualbox
Bringing machine 'default' up with 'virtualbox' provider...
...
Whoa! Why did it bring up default
? According to the Vagrantfile
docs the Vagrantfile packaged with the box should be used, and other Vagrantfile
s including from the current directory should be merged into it. But this does not seem to be the case.
Vagrant 1.7.2 is the version in use.
I would like workshop participants to be able to bring up the VMs defined in the Vagrantfile
included in the box, without supplying that Vagrantfile
out of band (in order to minimise dependencies). Have I missed something important?