Monday, November 28, 2011

Using Vagrant

Vagrant is a great tool for creating vm at whim and tearing it down so that you could start all over again. It helps to start from a clean state, when you are trying to test deployment and setups. Vagrant requires VirtualBox and is written in Ruby.

Following is a step by step take down on how to setup and use vagrant on Mac



 Requires Ruby 

Using "RVM" is a great way to use ruby and ruby apps

curl -s https://rvm.beginrescueend.com/install/rvm -o rvm-installer
chmod +x rvm-installer
./rvm-installer --version latest

Add the following in bash profile:

# This loads RVM into a shell session
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

Install Ruby

rvm install ruby-1.9.2
rvm --default use 1.9.2

Install virtualbox 

wget http://download.virtualbox.org/virtualbox/4.1.4/VirtualBox-4.1.4-74291-OSX.dmg

Install Vagrant

gem install vagrant

Using vbox to create a VM

Create a directory for project:

mkdir dummyproject
cd dummyproject

Get a Ubuntu box:

vagrant box add lucid64 http://files.vagrantup.com/lucid32.box

Initialize current folder for Vagrant usage:

vagrant init lucid64

Creates the vagrant environment & VM:

vagrant up

Various vagrant commands:

SSH into the instance: vagrant ssh ; sudo su - root
Reboot:                vagrant reload
Save and suspend:      vagrant suspend
Destroy:               vagrant destroy


Sidenotes

Where is the information on added boxes stored?

In folder ".vagrant.d" in your home directory:
ls -la ~/.vagrant.d/boxes/
total 0
drwxr-xr-x  4 user1  staff  136 Oct 25 14:10 .
drwxr-xr-x  5 user1  staff  170 Oct 25 14:02 ..
drwxr-xr-x  6 user1  staff  204 Oct 25 14:04 lucid64
drwxr-xr-x  7 user1  staff  238 Oct 25 14:11 puppet-rhel-6-64

Where to get flavors of OS boxes?

At http://www.vagrantbox.es:

CentOS, Ubuntu, Debian, Solaris, Redhat

Just do the following:

vagrant box add puppetrhel60-64 http://puppetlabs.s3.amazonaws.com/pub/rhel60_64.box
vagrant init puppetrhel60-64
vagrant up

Vagrantfile

In the directory, where you did "vagrant init ..", a file called "Vagrantfile" is created.


Contents of Vagrantfile:

Vagrant::Config.run do |config|
  # All Vagrant configuration is done here.
  # Every Vagrant virtual environment requires a box to build off of.
  config.vm.box = "lucid64"
  # Url from where the 'config.vm.box' box will be fetched, if not in system
  config.vm.box_url = "http://domain.com/path/to/above.box"
  # Boot with a GUI so you can see the screen. (Default is headless)
  # config.vm.boot_mode = :gui
end

This explains the "Three important things":

  • The box name to bootup in VirtualBox. 
  • This should be available via "Vagrant box add .." 
  • Or you could make this available via the url from where it could be fetched 
  • Do you want the GUI or you could do with just SSH 


You could do more with vagrantfile:


Vagrant::Config.run do |config|
 config.vm.network "33.33.33.10"
 config.vm.forward_port("http", 80, 8080)
 config.vm.share_folder("v-data", "/vagrant_data", "../data")
end


  • Normally you ssh into this VM via vagrant ssh 
    • Sometime it makes sense to access it through an IP address. 
    • This can be achieved through setting of config.vm.network 
  • Also you want to access, say "httpd" running on port 80 on VM, from another machines 
    • You could forward the "port 80" on the vm to your machine on some port say "8080"
  • Last configuration is merely for ease. 
    • You already have suitable editors etc installed on your machine. You could easily edit files on your VM via tools on your machine through this "shared folder" mapping


6 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. “Abortion pill” is the common name for using two different medicines to end a pregnancy: mifepristone and misoprostol.

    First, you take a pill called mifepristone. Pregnancy needs a hormone called progesterone to grow normally. Mifepristone blocks your body’s own progesterone, stopping the pregnancy from growing. obat penggugur kandungan

    ReplyDelete
  3. Hendel Forex merupakan sebuah
    obat pembesar vital asli dari Itali yang bersifat herbal dan dikemas dalam bentuk kapsul agar setiap konsumen akan lebih mudah ketika mengkonsumsi obat kuat serta penambah ukuran pada penis pria yang satu ini. Satu botol Hendel Forex, berisikan 30 butir kapsul yang diimpor langsung dari Itali.

    ReplyDelete
  4. thank you for the information you provided
    may be useful for all of us
    don't forget to click
    OBAT PEMBESAR PENIS

    ReplyDelete
  5. That’s a great article! The neatly organized content is good to see. Can I quote a blog and write it on my blog? My blog has a variety of communities including these articles. Would you like to visit me later?
    경마사이트
    경마

    ReplyDelete