Vagrant: Productivity for both Developers and SysAdmins

Update Feb 22, 2012: I just found out another ‘cool’ tool at using vagrant for local image and with EC2 instance.

Vagrant is a productive tool in building and distributing virtual images for development.

1. Setup Virtualbox
2. Setup RVM
3. Install Ruby 1.9.2 inside RVM
4. Install Vagrant

$ gem install vagrant
$ vagrant box add base

5. Install chef (optional)

Once everything is set, a simple configuration on Vagrantfile can have the lines: do |config| = "lucid32" ""


Start initializing and running our base image:

$ vagrant init base
$ vagrant up 
$ vagrant ssh

Now to start with chef-solo, you can download the getting started cookbooks:

Adding more cookbooks later, I need to generate the metadata.json.

$ cd /tmp
$ wget -O cookbook-ops.tgz
$ tar -zxvf cookbook-ops.tgz
$ cd ops* 
$ knife cookbook metadata -a  -o ./ 

Generating metadata for 7-zip from /tmp/opscode-cookbooks-c156223/7-zip/metadata.rb
Generating metadata for activemq from /tmp/opscode-cookbooks-c156223/activemq/metadata.rb
Generating metadata for ant from /tmp/opscode-cookbooks-c156223/ant/metadata.rb

In my case, I copy only the nginx cookbook to vagrant cookbook directory, now the cookbook directory:


I need to edit the cookbooks/vagrant_main/recipes/default.rb for nginx:

require_recipe "apt"
require_recipe "nginx"

Now the new Vagrantfile will have the lines: do |config| = "lucid32" ""

  config.vm.provision :chef_solo do |chef|
     chef.log_level = "debug"
     chef.cookbooks_path = "cookbooks"
     chef.add_recipe "vagrant_main"

And then we can start provisioning:

$ vagrant provision 

[default] Running provisioner: Vagrant::Provisioners::ChefSolo...
[default] Generating chef JSON and uploading...
[default] Running chef-solo...
[default] stdin: is not a tty

$ vagrant ssh
Linux lucid32 2.6.32-33-generic #70-Ubuntu SMP Thu Jul 7 21:09:46 UTC 2011 i686 GNU/Linux
Ubuntu 10.04.3 LTS

Welcome to Ubuntu!
 * Documentation:
Last login: Fri Dec  2 01:27:30 2011 from
vagrant@lucid32:~$ sudo netstat -lp | grep www
tcp        0      0 *:www                   *:*                     LISTEN      739/nginx       

Our nginx is running. 🙂 Let’s package our new nginx VM.

$ vagrant package --include Vagrantfile
[default] Attempting graceful shutdown of linux...
[default] Clearing any previously set forwarded ports...
[default] Cleaning previously set shared folders...
[default] Creating temporary directory for export...
[default] Exporting VM...
Progress: 0%Progress: 14%Progress: 28%Progress: 31%Progress: 34%Progress: 36%Progress: 46%Progress: 48%Progress: 57%Progress: 61%Progress: 68%Progress: 83%Progress: 86%Progress: 93%[default] Compressing package to: /Users/cocoy/vagrant/lucid32/
[default] Packaging additional file: Vagrantfile

For distribution and restoring the new image:

$ vagrant box add newlucid 
[vagrant] Downloading with Vagrant::Downloaders::File...
[vagrant] Copying box to temporary location...
[vagrant] Extracting box...
[vagrant] Verifying box...
[vagrant] Cleaning up downloaded box...

Note: We can edit the Vagrantfile to change the IP first if we need to.

$ vagrant up
[default] Importing base box 'newlucid'...
[default] The guest additions on this VM do not match the install version of
VirtualBox! This may cause things such as forwarded ports, shared
folders, and more to not work properly. If any of those things fail on
this machine, please update the guest additions and repackage the

Distributing VM’s for developers to sync configs/software packages/files with production setup is easy.
Easy replication of servers via chef-solo recipes.
Testing integration with different parts of the system may it be database, cache servers, or web servers.

Good references about Vagrant:
Vagrant Getting Started

Leave a Reply

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