Vagrant - Virtualized development for the masses
What is Vagrant?
Development environments made easy.
Create and configure lightweight, reproducible, and portable development environments.
Why Vagrant Changes Everything
Vagrant lowers development environment setup time, maximizes dev/prod parity, and makes the "works on my machine" excuse a relic of the past.
Developers no longer need to worry about setting up complicated infrastructure components. Projects with conflicting dependencies can each get their own sandbox -- keeping a developer's workstation free of the hacks needed for multiple versions of software to coexist.
Operations engineers no longer need to worry about developers having a different local setup from production. They can experiment and test their configuration management changes before going live.
Not convinced? Read more about why Vagrant is right for you.
Installation
Install using the operating system specific package
Debian/Ubuntu - deb package
Arch Linux - pkg.tar.xz
RHEL/CentOS/Oracle - rpm package
Windows - msi
Mac OS X - dmg
Install as gem - platform independent, ONLY recommended for 1.0.x
$ gem install vagrant $ vagrant box add {title} {url} $ vagrant init {title} $ vagrant up
Setup Your First Instance
Vagrant is so easy to use that you can get your first virtual machine up and running in just 3 easy steps:
$ vagrant box add precise64 http://files.vagrantup.com/precise64.box $ mkdir precise64 $ cd precise64 $ vagrant init precise64 $ vagrant up
Vagrant
Boxes
Installing a Box
Boxes can be installed from the filesystem or via HTTP (note that if you’re interested, it’s quite easy to extend this to support more protocols). No matter the source, the installation method is the same. The following adds a box named precise64 to a local vagrant installation
$ vagrant box add precise64 http://files.vagrantup.com/precise64.box
Since vagrant 1.2.x, user can specify the provider that backs the box by using the --provider option
Usage: vagrant box add <name> <url> [--provider provider] [-h] -f, --force Overwrite an existing box if it exists. --insecure If set, SSL certs will not be validated. --provider provider The provider that backs the box. -h, --help
The name used with the vagrant box add command is the name used to reference the box from that point forward. Any box can be named anything you want. Boxes that are added using vagrant box add are global to the vagrant install, and they are stored at ~/.vagrant.d/boxes on the local filesystem.
Note: The default Vagrantfile created with vagrant init defaults to using a box named "base". It is a good practice to specify a proper name. The name of the box is NOT significant in any way other than to logically identify the box in a Vagrantfile or from the command line.
Removing Boxes
Boxes can be removed (the deletion is permanent) from ~/.vagrant.d/boxes. The following is an example command to remove a box.
$ vagrant box remove box_name
If you tried to run this command, it will obviously fail, since you haven’t added a box named "box_name" yet.
Once a box is removed, no new virtual machines based on that box can be created, since it is completely deleted off the filesystem, but existing virtual machines which have already been spun up will continue to function properly.
Destroying Boxes
Once you have finished testing and don't need the test environment (instance) any more, you can destroy (delete it from VirtualBox Default Machine Folder) with vagrant destroy.
$ vagrant destroy box_name
Change Vagrant Home
By default VAGRANT_HOME is ~/.vagrant.d
To change it, in terminal
export VAGRANT_HOME=/path/to/vagrant
To make it permanent, add the above to ~/.bash_profile (works for Interactive login shell and Non-interactive login shell).
Cheat sheet
Commands
Most users will use these commands every days:
vagrant status
vagrant status # has box? vagrant box # add remove list or package box vagrant init # build Vagrantfile vagrant up # turn on the box vagrant suspend # pause the box vagrant resume # resume the box vagrant halt # shutdown box vagrant reload # restart box vagrant destroy # destroy the test environment vagrant ssh # open box vagrant provision # run provisioner
For more on these commands, please check the built in help:
vagrant gem -h vagrant package -h vagrant ssh-config -h
Vagrant Plugins
Chef
Local Domain Resolution
/etc/resolver approach
- vagrant-dns (using rubydns)
- vagrant-dnsmasq (using dnsmasq)
/etc/hosts approach
Providers
- vagrant-aws
- vagrant-digitalocean
- vagrant-hp
- vagrant-joyent
- vagrant-kvm
- vagrant-libvirt
- vagrant-lxc
- vagrant-openstack
- vagrant-rackspace
- vagrant-managed-servers
Provisioners
See => https://github.com/mitchellh/vagrant/wiki/Available-Vagrant-Plugins
Vagrant Base Boxes
A list of places where you can get all sorts of vagrant base boxes for different purposes: development, testing or even production.
- A list of A lit of base boxes for Vagrant
vagrantbox.es - Opscode bento (Ubuntu, Debian, CentOS, Fedora)
https://github.com/opscode/bento URLs and Veewee definitions
NOTE: For hidden bento boxes, access the root context of AWS S3 storage server directly => https://opscode-vm-bento.s3.amazonaws.com/ - Puppet Labs Vagrant Boxes
http://puppet-vagrant-boxes.puppetlabs.com/
Veewee definitions https://github.com/puppetlabs/puppet-vagrant-boxes - Vagrant Cloud Images - Ubuntu
- http://cloud-images.ubuntu.com/vagrant/
Reference
Vagrant Getting Started Guide v1 v2
http://railscasts.com/episodes/292-virtual-machines-with-vagrant