Vagrant : quickly deploy virtual machines
Software version | |
---|---|
Operating System | Debian 7 |
Website | Vagrant Website |
Last Update | 13/03/2014 |
Others | VirtualBox |
1 Introduction
Vagrant provides easy to configure, reproducible, and portable work environments built on top of industry-standard technology and controlled by a single consistent workflow to help maximize the productivity and flexibility of you and your team.
To achieve its magic, Vagrant stands on the shoulders of giants. Machines are provisioned on top of VirtualBox, VMware, AWS, or any other provider. Then, industry-standard provisioning tools such as shell scripts, Chef, or Puppet, can be used to automatically install and configure software on the machine.
2 Installation
We need to install those prerequisites in order to install VirtualBox in the wished version :
aptitude |
aptitude install libsdl-ttf2.0-0:amd64 gcc-4.6-base:amd64 cpp-4.6 dkms gcc-4.6 linux-headers-amd64 linux-kbuild-3.2 |
Then get this VirtualBox and vagrant version ot avoid incompatibility versions :
3 Usage
Each created instances should have it's own folder. For example you can do this kind of hierarchy :
. |-- Vagrant | |-- vm1 | |-- vm2 | `-- vm3
3.1 Add an image
The first thing you have to do is to add an image. You can find several ones here[1] or to the official Vagrant Cloud[2]. Let's take a Debian Squeeze for example (change squeeze name if you want) :
vagrant |
vagrant box add squeeze http://www.emken.biz/vagrant-boxes/debsqueeze64.box |
This will download and store the image in ~/.vagrant.d/boxes/.
Here is an Wheezy image :
vagrant box add deimosfr/debian-wheezy |
Or Jessie:
vagrant box add deimosfr/debian-jessie |
3.2 Deploy an image
To deploy a downloaded box image, simply run that :
vagrant |
vagrant init <squeeze> |
Replace squeeze by what the name of the box. This will create a Vagrantfile file.
3.3 Start the image
To start an image, it's simple :
vagrant |
vagrant up |
3.4 Stop the image
You can shutdown :
vagrant |
vagrant halt |
3.5 Connect to the image
To connect through ssh, it's simple :
vagrant |
vagrant ssh |
3.6 List all boxes machines
To list all available boxes on your machine :
vagrant |
> vagrant box list squeeze (virtualbox) |
4 Plugins
4.1 VirtualBox Guest Additions
To avoid reinstalling manually each new version of guests, here is a plugin that will do it for you each time you boot a vm ! Install the plugin:
vagrant plugin install vagrant-vbguest |
That's it :-). Now start a VM and if VirtualBox Guests Additions are not at the latest version, they will automatically be updated.
5 Example
5.1 Ceph
Here is an example for 6 VMs with 2 interfaces :
To boot them, simply "vagrant up".
6 Conclusion
I've wrote here basics commands as an introduction but you can do more than that with Vagrant. Read the documentation for more informations[3].
7 FAQ
7.1 VirtualBox is complaining that the kernel module is not loaded
If you got this kind of error message while doing a "vagrant up" command :
VirtualBox is complaining that the kernel module is not loaded. Please run `VBoxManage --version` to see the error message which should contain instructions on how to fix this error.
You need to install your kernel sources or kernel headers package and launch modules compilation :
> /etc/init.d/vboxdrv setup [ ok ] Stopping VirtualBox kernel modules:. [ ok ] Recompiling VirtualBox kernel modules:. [ ok ] Starting VirtualBox kernel modules:. |