vagrant in 15 minutes

11

Click here to load reader

Upload: anton-weiss

Post on 15-Jul-2015

120 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Vagrant in 15 minutes

Vagrant for

Devs

Page 2: Vagrant in 15 minutes

• What is Vagrant for? • Installation • Project Setup • Vagrant Boxes • Up and Running • Provisioning • Teardown • Wrap Up

Page 3: Vagrant in 15 minutes

•Kill the ‘Works on my Machine’ syndrome

•Dev environments that are: •Easy to configure •Reproducible •Portable •Disposable •Self-contained

Why Vagrant?

Page 4: Vagrant in 15 minutes

• Go to http://www.vagrantup.com/downloads • Download the appropriate package • Run the installer • Check the installation:

> vagrant -v Vagrant 1.6.3

Installation

Page 5: Vagrant in 15 minutes

• 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

Page 6: Vagrant in 15 minutes

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

Page 7: Vagrant in 15 minutes

$ 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

Page 8: Vagrant in 15 minutes

• 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

Page 9: Vagrant in 15 minutes

$ 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

Page 10: Vagrant in 15 minutes

• 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

Page 11: Vagrant in 15 minutes

Ant(on) Weiss DevOps Evangelist&Enabler, CI/CD/ALM Expert now at PrimaryData Inc. [email protected] twitter: @antweiss http://otomato.wordpress.com