Framework of the week: Vagrant

Purpose

Vagrant is framework that help you boot VMS easily.
So with just a little descriptor file, you’ll be able to start, execute some scripts, halt and stop a/some System(s).

Concepts

There are just few concepts on Vagrant that make this product useful.
First of all, the vagrant boxes repository listing all the public GA available packaged VMs (you can easily create yours following this tutorial.

You’ll then be able to provision a Vagrant file bridging your network card, executing some ‘Chef’ recipes (there will be an other ‘framework of the week’ on it later) or Puppet scripts (so automating package deployment and configuration on the target platform.

Finally, you’ll have three commands to start a new VM instance, stop and destroy it.

In a more global vision, Vagrant is the first brick needed to step forward to infrastructure as code, then test driven infrastructure.

Getting started

As a prerequisite, you must have installed VirtualBox, RubyGem and Vagrant

Let import a disc image from the VMs repository:

vagrant box add FedoraVM http://static.stasiak.at/fedora-18-x86-2.box

So now, we can initialize the VagrantFile where we’ll bind it to our configuration:

vagrant init FedoraVM

So now, we can tweak (or not) the generated Vagrant file.
An example for making your network available in public

config.vm.network :public_network, :bridge => "en5: Ethernet Thunderbolt"

Or for making a shared folder between the host and the client

config.vm.synced_folder "shared-folder", "/tmp/shared"

You can also execute some Chef recipes (package install and configuration at the box startup):

config.vm.provision :chef_solo do |chef|
     chef.cookbooks_path = "cookbooks"
     chef.roles_path = "roles"
     chef.add_recipe "httpd"
end

And finally you just have to “vagrant up”, “vagrant halt” or “vagrant destroy” the VM.

Note that you can tweak the file to boot up multiple VMs to test interactions between multiple machines.

Useful links

Vagrant doc
Vagrant up and running

Share Button

Leave a Reply

Your email address will not be published. Required fields are marked *