Vagrant: EC2-Like Virtual Machine Building and Provisioning from Ruby
Vagrant is a Ruby-based tool for building and deploying virtualized development environments. It uses Oracle's open-source VirtualBox virtualization system along with the Chef configuration management engine along with lots of Ruby goodness to automate the creation and provisioning of virtual machines for development purposes.
If you thought rolling out new VMs using Amazon EC2 was easy, Vagrant brings an even simpler system to your local development machine. From the command line, starting is as easy as:
sudo gem install vagrant
vagrant box add base http://files.vagrantup.com/base.box
mkdir vagrant
vagrant init
vagrant up
Be warned, though - as a 370MB download, adding that box image isn't a quick process! Once you've got it though, you can keep rolling out VMs based on it at will.
Note that VirtualBox is a separate dependency for Vagrant. Vagrant does not come with VirtualBox built in or anything like that. Download VirtualBox for your OS if you want to try Vagrant.
Beyond the basics of getting a VM running, Vagrant can take care of port forwarding, distribution, environment setup, SSH access, shared folders and, importantly, the provisioning of software onto the VM using Chef. If you want to automatically roll out a VM with Apache 2, Rails, Phusion Passenger, or the like, Chef and Vagrant will take care of it for you. This is powerful stuff!
In terms of documentation and having a straight forward official homepage, Vagrant sets a solid benchmark. There's a straightforward guide to getting started with Vagrant, lots of documentation, and a 12 minute getting started video/screencast. Great work guys!
March 8, 2010 at 11:00 pm
Serves me right for finishing the post while downloading that box image.. when I did vagrant up, I get an error message *groan*:
If I get it sorted out, I'll post again. This is on OS X 10.6..
March 8, 2010 at 11:03 pm
Digging deeper into the instructions seems to show that making a separate folder then running vagrant init is better. I tried that and got a totally different exception:
March 8, 2010 at 11:06 pm
Suspecting this isn't as clever as I thought it was and that I actually need to install VirtualBox separately first ;-) Giving that a go.
March 8, 2010 at 11:11 pm
Aha, that's a bingo! Updating post..
March 8, 2010 at 11:23 pm
All working now and post has been updated with further instructions. Still having issues rolling out multiple VMs at a time though, but investigating that further.. will post anything useful I get.
March 8, 2010 at 11:28 pm
OK. If you want multiple VMs for now, create multiple directories, do vagrant init in each, then add a config setting to each Vagrantfile forwarding a different port to each for SSH (or other) purposes, e.g:
config.vm.forward_port("ssh", 22, 10001)
And on another..
config.vm.forward_port("ssh", 22, 10002)
And so forth.
March 8, 2010 at 11:51 pm
Peter,
Thanks for the article! Quick, too!
Sorry about the trouble you had getting multiple VMs up at the same time. Multiple VMs within a single project is something I'd like to do in the future so Vagrant can be used to model more complex web applications more accurately (such as load balancers, separate utility servers, and so on), but its something which was just too complicated to get out with an initial release.
It seems that John helped you get it all working. Fantastic.
Thanks again!