Sunday, October 21, 2012

notes: Vagrant

(placeholder for Vagrant article)


* Vagrant

Vagrant lets you fire up multiple virtual machines (VMs) inside your normal
computer.  This lets you test multiple operating systems, or to switch
back to old projects. A virtual machine will have all the right
versions of the right packages installed, so you concentrate on
development, not on fiddling with the system.

It's easy to create a 'base' VM with specific changes.  Then create a
new VM based on this, make changes, and wipe them away easily.  This
is fantastic for testing: you can guarantee the VM is "clean", having
exactly what you want on it and nothing more.

** install Vagrant

$ sudo apt-get install vagrant

** tell Vagrant about Ubuntu Precise Pangolin

This takes a while, as it downloads a ~700MB ISO.

$ vagrant box add precise32 http://files.vagrantup.com/precise32.box

** create a new VM, using 'precise32' as a base

$ mkdir mybase
$ cd mybase
$ edit Vagrantfile

Vagrant::Config.run do |config|
  config.vm.box = "precise32"
end

** boot new VM

This will take a while, as Ubuntu installs itself to the virtual
disk.

$ vagrant up

[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!

** test new VM

$ vagrant ssh -c hostname

precise32

** fix networking

*** add nameserver

$ vagrant ssh -c 'sudo bash -c "echo nameserver 4.2.2.2 > /etc/resolv.conf"'

*** verify

$ vagrant ssh -c 'dig yahoo.com'

;; ANSWER SECTION:
yahoo.com.        3186    IN    A    98.139.183.24


** add important packages to the base VM

$ vagrant ssh -c 'sudo apt-get -y install fortune-mod vim'

** package base box with changes, make available for re-use

$ vagrant package    # takes about a minute

$ vagrant box add mybase $PWD/package.box

** make a new VM with the better base

$ mkdir ../apple
$ cd ../apple
$ edit Vagrantfile

Vagrant::Config.run do |config|
  config.vm.box = "mybase"
end

** boot new VM and test it

$ vagrant up    # takes a couple minutes

$ vagrant ssh -c fortune

The man who sets out to carry a cat by its tail learns something that
will always be useful and which never will grow dim or doubtful.
        -- Mark Twain





No comments:

Post a Comment