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

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

$ mkdir mybase
$ cd mybase
$ edit Vagrantfile do |config| = "precise32"

** boot new VM

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

$ 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


** fix networking

*** add nameserver

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

*** verify

$ vagrant ssh -c 'dig'

;; ANSWER SECTION:        3186    IN    A

** 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/

** make a new VM with the better base

$ mkdir ../apple
$ cd ../apple
$ edit Vagrantfile do |config| = "mybase"

** 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