30.4.12

Vagrant : baby steps

Vagrant can build, and destroy, your entire dev setup in a matter of minutes.  Its a powerful tool for achieving a cleanroom enginerring deployment setup.

Vagrant allows you to setup a personalized VM on any machine in a matter of minutes - and reduces the tedium associated with building a local virtualbox environment which mimics a server.  To specify your VM, you can provision (1) an OS version by name and url (vagrant will fetch it for you) and (2) A provisioner - (i.e. this could simply be a shell script which runs after the base box is set up.)  The two commands "vagrant up" and "vagrant destroy" are then all you need to build and tear down your development environment in a matter of seconds.





I've given up on alot of things in my life, especially including the idea of managing software on my development machine.   Im not a sysadmin guy but... vagrant is really cool so I'm forcing myself to start using it.  Also DanielKnell told me to... so... Here's how I got a vagrant VM environment running on ubuntu.

(Vagrant requires a solid Ruby setup - heres what i did to get it working.)

First, install ruby and the ruby bundler :

sudo apt-get install ruby-bundler

To do this , create a directory, cd to it, and create a gem file that looks like this.

source 'http://rubygems.org'
gem 'vagrant', "~> 0.8.1"
gem 'veewee', "~> 0.2.0"  

(note that veewee isn't really necessary here).

THEN 

run the bundle install via the gemfile : 

$> sudo bundle install

Now... In ubuntu 10, I had to update ruby gems to avoid this crazy error related to date formats : 

$>sudo gem install rubygems-update
$>update_rubygems

Now, both veewee and vagrant are installed.
Lets build a VM !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

You can borrow a full blown vm base box to start :


vagrant box add base https://s3.amazonaws.com/cloudbiolinux/cbl_ubuntu_11_4_32_20110628.box  

Or, simpler and faster one like this : 

vagrant box add ubuntu-lucid-32 http://files.vagrantup.com/lucid32.box
Next, before I install it - How do I customize it ? 

Vagrant has a set "Vagrantfile" that is initialized for you. This file is created with the "vagrant init my-base-box" command.  For example :

vagrant init ubuntu-lucid-32

So, you first can initialize vagrant via the init command, followed by the box name, and then you can edit the contents of the "Vagrantfile" to point to a shell script which executes some custom instructions, i.e. installing programs.

Now what ?

Now, you can get into your vm :

vagrant ssh

Yipeeee.

Now, as long as you commit changes to the ssh file associated with your Vagrant , anyone can run this vagrant up command, from anywhere, to recreate your environment.

Finally - if you screw up the environment, you can run "vagrant destroy" followed by "vagrant up" to refresh it to the original start point.

------- UPDATES --------

Just found got this wonderful piece of advice on irc #vagrant :


bgy_Jayunit100: vagrant reload should reboot the box, or you can do it manually by chaining vagrant halt && vagrant up
4:24pmJayunit100aha thanks !

Oh and watch out for this :


Jayunit100reload appears to be provisioning ?
4:28pmadt22is that a problem?
4:28pm....
4:31pmadt22yeah: vagrant reload --no-provision







2 comments:

  1. Cool, didn't know you were into Ruby. What are you using it for?

    ReplyDelete
    Replies
    1. Yo : just to run vagrant. Remember the connjur-vm project that got killed ? Well it was tough to maintain because i had to keep exporting ISO images. Now, with vagrant you can build a "BASE BOX" from the large repo of existing base boxes on the vagrant (or on other sites), and then run the Vagrantfile to customize it to your needs (Vagrant file ultimately just runs puppet or a shell script). Vagrant comes out of the box ready for development - its kind of like a shortcut to building a VM for development, because its preconfigured to run in virtual box's env, in the background, with no GUI, and setup port forwarding / local file shares, etc etc etc.

      Delete