Table of Contents

Vagrant

Vagrant is NOT an hypervisor in anyway, although it is of great use when developing software that is ultimately deployed onto a virtualized environment. From the Vagrant website:

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.

Introduction to Vagrant

In a few words:

Vagrant uses Oracle’s VirtualBox to create its virtual machines and then uses Chef or Puppet to provision them.
Once you or someone else creates a single Vagrantfile, you just need to vagrant up and everything is installed and configured for you to work.

A very well made introduction to Vagrant (with video) can be viewed on the SysadminCasts.com episode #04. Or you could directly view the revised Episode #42 - Crash Course on Vagrant.

Vagrant makes it easy to create disposable environments for testing scripts and infrastructure changes.

Environment

What follows is mainly taken from this smashingmagazine.com article.

As stated earlier, Vagrant is NOT an hypervisor but it needs one to work in collaboration with. Vagrant is compatible with lots of providers as they call them.

In the following we'll be using VirtualBox as it is freely available for most platforms.


Vagrant Installation

Download Vagrant

Download the Vagrant installer for your OS from the Vagrant download page, then launch it and complete the install procedure.

OSX / Linux File Systems

In order for Vagrant to be able to cope with OSX or Linux file systems, we'll need to issue the following command in a terminal:

> sudo vagrant plugin install vagrant-bindfs

Vagrant Host Manager

Run the next command to install Vagrant Host Manager to save you editing your hosts file by hand.

> sudo vagrant plugin install vagrant-hostmanager

Vagrant Boxes & Templates

What follows mainly comes from the sysadmincasts.com episode #05 and episode #42.

In Vagrant, the term box represents what's usually defined as a virtual machine.

Vagrant init allows you to initialize a new Vagrant environment.
A Vagrant environment can be a single Vagrant virtual machine, or a collection of virtual machines. So, an environment will describe what boxes, or virtual machines to boot, along with all of the associated settings, through a configuration file called a Vagrantfile.
You can define really complex environments through a single configuration file, then share that with other people. The added bonus, is that your environments are self documenting, in that it is easy to read the configuration file and see what is going on.

Custom Vagrant Box Using Veewee

The following requires VirtualBox, Ruby, and Vagrant to be installed.

Install Veewee

> sudo gem install veewee

In case you get an error of type:

ERROR:  Error installing veewee:
	ERROR: Failed to build gem native extension.

    /usr/bin/ruby2.1 extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.1.0/gems/posix-spawn-0.3.11 for inspection.
Results logged to /var/lib/gems/2.1.0/extensions/x86_64-linux/2.1.0/posix-spawn-0.3.11/gem_make.out

You need to install the ruby-dev library:

> sudo apt-get install ruby-dev

List available Veewee templates

To list available templates issue the following command:

> veewee vbox templates
> veewee vbox templates | grep -i debian

Define a new basebox off and existing template

We'd like to set up a Debian 8.2 box, but there is only a Debian-7.6.0-amd64-netboot template available, let's start with this one:

> veewee vbox define 'debian-8.2-amd64' 'Debian-7.6.0-amd64-netboot' --workdir=/home/user/Vagrant

At this stage we have a definitions directory that was created under /home/user/Vagrant (our workdir). Inside this directory is another one named debian-8.2-amd64 after our previous veewee vbox define command options. Inside this definitions directory we'll look at two files:

definition.rb

Change the following lines:

...
  :iso_file => "debian-7.6.0-amd64-netinst.iso",
  :iso_src => "http://mirror.i3d.net/pub/debian-cd/7.6.0/amd64/iso-cd/debian-7.6.0-amd64-netinst.iso",
  :iso_md5 => "8a3c2ad7fd7a9c4c7e9bcb5cae38c135",
...
     'console-keymaps-at/keymap=us ',
     'keyboard-configuration/xkb-keymap=us ',
...
     'kbd-chooser/method=us ',
...

To this:

...
  :iso_file => "debian-8.2.0-amd64-netinst.iso",
  :iso_src => "http://cdimage.debian.org/debian-cd/8.2.0/amd64/iso-cd/debian-8.2.0-amd64-netinst.iso",
  #:iso_md5 => "8a3c2ad7fd7a9c4c7e9bcb5cae38c135",
...
     'console-keymaps-at/keymap=fr ',
     'keyboard-configuration/xkb-keymap=fr ',
...
     'kbd-chooser/method=fr ',
...

The iso_md5 parameter is commented out as I couldn't figure out where to find this for Debian releases :-\

preseed.cfg

Change the following lines:

...
# Keyboard selection.
#d-i keymap select us
d-i keyboard-configuration/xkb-keymap select us
...
d-i partman/default_filesystem string ext3
...
# Individual additional packages to install
d-i pkgsel/include string openssh-server ntp acpid  sudo bzip2 rsync
...
#d-i grub-installer/bootdev  string (hd0,0)
...

To this:

...
# Keyboard selection.
#d-i keymap select us
d-i keyboard-configuration/xkb-keymap select fr
...
d-i partman/default_filesystem string ext4
...
# Individual additional packages to install
d-i pkgsel/include string openssh-server ntp acpid sudo bzip2 rsync ruby-dev
...
d-i grub-installer/bootdev  string /dev/sda
...

Adding ruby-dev is mandatory here as otherwise an error will be thrown when trying to install some gems.

Local iso repository

We can create an iso directory in our workdir where downloaded iso will be stored for future usage (avoiding recurrent downloads).

> mkdir /home/user/Vagrant/iso

Build the box

We can now tell Veewee to build our Debian 8.2.0 box:

> veewee vbox build 'debian-8.2-amd64'

Server Profile

The objective of using Vagrant being to have a development environment exactly identical to the deployment one, it might be necessary to profile your targeted deployment environment. For example, if you're planning to use a specific web server at, let's say DigitalOcean, you might want to set this up, and find out about the server's configuration details.

OS Version

You can use the following command lines to gather information regarding the current OS:

> cat /etc/*-release

PRETTY_NAME="Debian GNU/Linux 7 (wheezy)"
NAME="Debian GNU/Linux"
VERSION_ID="7"
VERSION="7 (wheezy)"
ID=debian
ANSI_COLOR="1;31"
HOME_URL="http://www.debian.org/"
SUPPORT_URL="http://www.debian.org/support/"
BUG_REPORT_URL="http://bugs.debian.org/"
> cat /proc/version

Linux version 3.2.0-4-amd64 (debian-kernel@lists.debian.org) (gcc version 4.6.3 (Debian 4.6.3-14) ) #1 SMP Debian 3.2.63-2
> lsb_release -a

No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 7.9 (wheezy)
Release:	7.9
Codename:	wheezy
> uname -a

Linux lamp-xdn 3.2.0-4-amd64 #1 SMP Debian 3.2.63-2 x86_64 GNU/Linux

Server software

Once you have the OS information, and in the case of a web server running php, you might use the phpinfo(); command in a .php file to output the detailed web configuration of the server.

Of course you may also want to have any specific system configuration for your application needs and start from a “blank” system…


Puppet Provisioning