Place Ghantoos

How to setup & run Oh-my-vagrant on Debian (with libvirt/KVM)

Tagged: , , , ,

Last friday, James Shubin (purpleidea) came to the Montreal Red Hat office to talk about his project: Oh-my-vagrant.

In a nutshell, Oh-my-vagrant (also called OMV) is a Vagrant wrapper, that helps you easily manipulate your dev environments. By easily, I mean: it’s a couple of minutes (sometimes seconds) before you have your env up’n’running with your favorite updated OS (centos, debian, rhel, and more), your own code and scripts (from github or elsewhere), your preferences, etc. All kinds of awesome!

You can find lot’s of documentation on the project page:

This post is intended to help you easily setup oh-my-vagrant on your Debian box. This requires Debian Jessie minimum.

First, you’ll need to install libvirt and its dependencies:

sudo apt-get install libvirt-bin libvirt-daemon libvirt-clients libvirt0

To allow your user to play with libirvt and kvm (and avoid using sudo), add them to the libvirt/kvm groups:

sudo adduser <your_username> kvm
sudo adduser <your_username> libvirt

Now let’s install vagrant and some of the plugins build dependencies:

sudo apt-get install vagrant ruby-libvirt libvirt-dev ruby-nokogiri zlib1g-dev

At this point you should have a functional vagrant environment on your machine.

In order for vagrant to use the libvirt/KVM back-end (instead of the default virtualbox), we will need to install some plugins (at the time of the post the plugins were not packaged into Debian (though an ITP was filed and people started to work on them)).

Let’s install vagrant’s libvirt plugin first:

vagrant plugin install vagrant-libvirt

Then vagrant’s host manager plugin:

vagrant plugin install vagrant-hostmanager

Now let’s clone the oh-my-vragrant repository, and start playing.

~$ git clone --recursive
~$ cd oh-my-vagrant/vagrant
~$ vagrant status
Current machine states:

omv1                      not created (libvirt)

The Libvirt domain is not created. Run `vagrant up` to create it.

You can now launch your first VM by typing: vagrant up

~$ vagrant up
Bringing machine 'omv1' up with 'libvirt' provider...
==> omv1: Box 'centos-7.1' could not be found. Attempting to find and install...
    omv1: Box Provider: libvirt
    omv1: Box Version: >= 0
==> omv1: Box file was not detected as metadata. Adding it directly...
==> omv1: Adding box 'centos-7.1' (v0) for provider: libvirt
    omv1: Downloading:
    omv1: Progress: 62% (Rate: 932k/s, Estimated time remaining: 0:04:38)

Note: after running it once, the image is cached locally for instant reuse.

It is as easy as that! You can now connect to your virtual machine by simply typing:

~$ vagrant ssh omv1

To destroy your environment:

vagrant destroy

The default omv.yaml file installs a centos; if you want to launch an Debian installation.

~$ cd oh-my-vagrant/vagrant/
~$ cp ../examples/debian.yaml omv.yaml
~$ vagrant up

As we are using the libvirt plugin with a KVM backend, all you virtual machines can be also managed with virsh(1) or Virtual Machine Manager.

You should check-out the omv.yaml file, it’s very easy to hack and offers plenty of very interesting features to automate your dev environment spawning. You’ll find more documentation on github.

Happy coding!

Tagged: , , , ,

Leave a Reply