vagrant in 15 minutes
TRANSCRIPT
Vagrant for
Devs
• What is Vagrant for? • Installation • Project Setup • Vagrant Boxes • Up and Running • Provisioning • Teardown • Wrap Up
•Kill the ‘Works on my Machine’ syndrome
•Dev environments that are: •Easy to configure •Reproducible •Portable •Disposable •Self-contained
Why Vagrant?
• Go to http://www.vagrantup.com/downloads • Download the appropriate package • Run the installer • Check the installation:
> vagrant -v Vagrant 1.6.3
Installation
• Vagrantfile 1. Mark the root directory of your project. 2. Configure the virtual environment:
Type of machine. Network. Storage sharing. Provisioning.
• vagrant init $ mkdir vagrant_getting_started
$ cd vagrant_getting_started $ vagrant init
• Commit Vagrantfile to Source Control
Project Setup
It all starts with a base Box!
Atlas Boxes Catalog :https://atlas.hashicorp.com/boxes/search Vagrantbox.es : http://www.vagrantbox.es
Add a box: vagrant box add hashicorp/precise32
Use the box: In Vagrantfile:
Vagrant.configure("2") do |config| config.vm.box = "hashicorp/precise32"
end
Vagrant Boxes
$ vagrant up• process the Vagrantfile • boot and configure the virtual machine
$ vagrant ssh• full-fledged ssh connection
$ ls /vagrant• default synced folder
$ vagrant destroy
Up and Running
• Supported provisioning types: • file, shell, Chef, Puppet, Ansible, Salt, Docker
• Example: Installing Apache bootstrap.sh :
Vagrantfile:
Vagrant.configure("2") do |config| config.vm.box = "hashicorp/precise32" config.vm.provision :shell, path: "bootstrap.sh" end
#!/usr/bin/env bash apt-get update
apt-get install -y apache2 if ! [ -L /var/www ]; then
rm -rf /var/www ln -fs /vagrant /var/www
fi
Provisioning
$ vagrant suspend save the state and pause the machine
$ vagrant halt gracefully shutdown the machine
$ vagrant destroy erase all trace of the guest machine
Teardown
• Self-contained Dependencies • Your environment is part of your codebase • Vagrantfile is all you need. • Download a base box or create one and share. • Work with any virtualisation provider. • Never look back!
Wrap Up
Ant(on) Weiss DevOps Evangelist&Enabler, CI/CD/ALM Expert now at PrimaryData Inc. [email protected] twitter: @antweiss http://otomato.wordpress.com