Overview
- A bit of background
- What is Vagrant?
- Why use Vagrant?
- Workflow
- Plugins
- Who uses Vagrant?
- Resources
Background
- Started January 2010 by Mitchell Hashimoto
- Remained a side project for 3 years
- November 2012 Mitchell formed Hashicorp
- Started as open source and will always remain open source
What is Vagrant?
Vagrant is a platform that sits on top of virtualisation software to provide automation of creating and provisioning virtual machine (VM) environments
WTF does that mean!?
- Host machine and VM provider for guest machines
- Typically start with an ISO image (Ubuntu, Fedora, Windows)
- Use VM provider to install the OS and set up networking, folder shares, hardware (CPU, Memory allocation), I/O devices etc...
- Start the box, hope everything works and install dependencies
- Vagrant removes these manual steps and provides automation using a Vagrantfile
- Vagrantfile is portable!
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.synced_folder "/path/on/host/web_root", "/web_root"
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
vb.gui = true
# Customize the amount of memory on the VM:
vb.memory = "1024"
end
config.vm.provision "file", source: "./install_mysql.sh", destination: "~/install_mysql.sh"
end
Why use Vagrant?
- Consistent environment - avoids "works on my machine" bugs
- Isolates dependencies and their configuration
- Portable
- Works on Windows, Linux and OSX
- Removes manual creation and provision process of VMs
- Easily spin up more VMs with a different environment to test against i.e. php53 to php56, apache to nginx
Workflow
One time run on the command line to initialise the box
- vagrant box add {title} {url}
- vagrant init {title}
Now the box has been downloaded and a Vagrantfile is present
- Clone repo to the host machine
- vagrant up
- Make changes and test
- Commit/push changes
- vagrant destroy
Plugins
- Vagrant has lots of plugins that can extend its functionality
- Plugins can be installed via `vagrant plugin install {name}`
- A really useful plugin is vagrant-vbguest
Note: Guest additions are designed to be installed on the guest OS to provide device drivers and system applications that improve the guest OS performance