Vagrant

Vagrant is a Ruby program to automate the installation and setup of virtual machines in VirtualBox. It allows to quickly setup an environment for testing purposes or software development.

Installation

Note: on our managed Linux workstation Vagrant is already installed.

Preparation

Start by adding an image of a preconfigured virtual machine to your system. You can find our collection of compact Vagrant boxes at https://share.phys.ethz.ch/~isg/vagrant/.

vagrant box add <boxname> <path/to/vm.box>

I.e., if you want to test out Debian Jessie you would do

vagrant box add jessie 'https://share.phys.ethz.ch/~isg/vagrant/jessie64-core.box'

The box will be copied to ~/.vagrant.d/. To get a list of the boxes that you have available use

vagrant box list

You should remove old boxes you no longer need to free disk space

vagrant box remove <boxname>

You can find more boxes on the internet at sites like http://www.vagrantbox.es/.

Creating and Using a Vagrant Box

Next you have to create an initial Vagrantfile — a configuration file — inside some directory

mkdir /path/to/new/vagrant/box
cd /path/to/new/vagrant/box
vagrant init <boxname>

For the example with Ubuntu precise above this would be

mkdir ~/precise-test
cd ~/precise-test
vagrant init precise

You may optionally edit the Vagrantfile to customize it to your needs. For instance the box name is defined as

config.vm.box = "boxname"

To start the box use

vagrant up

To connect to the box once it is started use

vagrant ssh

You will be logged in without password as the user vagrant. Use sudo to issue commands as root. The directory /vagrant corresponds to the directory where the Vagrantfile is.

To stop the Vagrant box log out and use

vagrant halt

Configuration Management

Vagrant reaches its full power in combination with a configuration management system, like ansible, to automate the installation of packages and deployment of settings in the virtual machine.

More Information

Read the documentation at https://www.vagrantup.com/docs/.