SlideShare a Scribd company logo
Vagrant: virtualise your
development environment
Michael Peacock
August 2012, SuperMondays
About Me
 @michaelpeacock
Head Developer @ Ground Six
Leading the development team and managing the
development process
We are a tech investment company: you bring ideas, we
partner and build the product
Author
Occasional Speaker
Virtualisation
Virtualisation

 Abstraction layer for your hardware
Virtualisation

 Abstraction layer for your hardware
 Lets multiple Operating Systems run concurrently, each
 running on their own virtual hardware
Virtualisation

 Abstraction layer for your hardware
 Lets multiple Operating Systems run concurrently, each
 running on their own virtual hardware
 Limited by your own physical hardware and your host
 machine
VirtualBox
VirtualBox


 www.virtualbox.org
VirtualBox


 www.virtualbox.org
 Virtualisation software tool
VirtualBox


 www.virtualbox.org
 Virtualisation software tool
 Provides the hardware abstraction layer and an
 interface for running VMs
Vagrant
Vagrant

www.vagrantup.com
 “Create and configure lightweight, reproducable, and
 portable development environments”
Vagrant

www.vagrantup.com
  “Create and configure lightweight, reproducable, and
  portable development environments”
Set of command line tools which interacts with and
automates VirtualBox
Vagrant

www.vagrantup.com
  “Create and configure lightweight, reproducable, and
  portable development environments”
Set of command line tools which interacts with and
automates VirtualBox
Designed around portability
Puppet



Provisioning Service
Why?
Why?
Quick start time for new team members
  Vagrant up: you have a development environment
Why?
Quick start time for new team members
  Vagrant up: you have a development environment
Server configuration can be version controlled
Why?
Quick start time for new team members
  Vagrant up: you have a development environment
Server configuration can be version controlled
Cross-platform: work from any machine
Why?
Quick start time for new team members
  Vagrant up: you have a development environment
Server configuration can be version controlled
Cross-platform: work from any machine
Work on multiple projects? Easy to pickup an old, legacy
project with its funky server configs
Why?
Quick start time for new team members
  Vagrant up: you have a development environment
Server configuration can be version controlled
Cross-platform: work from any machine
Work on multiple projects? Easy to pickup an old, legacy
project with its funky server configs
Can run multiple VMs independently
Why?
Quick start time for new team members
  Vagrant up: you have a development environment
Server configuration can be version controlled
Cross-platform: work from any machine
Work on multiple projects? Easy to pickup an old, legacy
project with its funky server configs
Can run multiple VMs independently
Doesn’t mess with your local, host machine
Some terms
Some terms


Host: Your physical machine
Some terms


Host: Your physical machine
Guest: The VM
Overview
Overview
1.Project specific configuration file
Overview
1.Project specific configuration file
2.Import base box
Overview
1.Project specific configuration file
2.Import base box
3.Boot up Virtual Machine
  1.Forward Ports
  2.Share folders
Overview
1.Project specific configuration file
2.Import base box
3.Boot up Virtual Machine
  1.Forward Ports
  2.Share folders
4.Configure / provision software
3 lines: up and running
3 lines: up and running
 # download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box

# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init

# Boot the VM based off the config file we created
vagrant up
3 lines: up and running
 # download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box

# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init

# Boot the VM based off the config file we created
vagrant up
3 lines: up and running
 # download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box

# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init

# Boot the VM based off the config file we created
vagrant up
3 lines: up and running
 # download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box

# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init

# Boot the VM based off the config file we created
vagrant up
3 lines: up and running
 # download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box

# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init

# Boot the VM based off the config file we created
vagrant up
3 lines: up and running
 # download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box

# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init

# Boot the VM based off the config file we created
vagrant up
3 lines: up and running
 # download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box

# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init

# Boot the VM based off the config file we created
vagrant up
3 lines: up and running
 # download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box

# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init

# Boot the VM based off the config file we created
vagrant up
3 lines: up and running
 # download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box

# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init

# Boot the VM based off the config file we created
vagrant up
3 lines: up and running
 # download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box

# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init

# Boot the VM based off the config file we created
vagrant up
3 lines: up and running
 # download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box

# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init

# Boot the VM based off the config file we created
vagrant up
Let’s try it...
Vagrant
Vagrant
Vagrant
Vagrant
SSH into the box
vagrant ssh
Whats happened?
Whats happened?

Downloaded a base box of Ubuntu, configured for
vagrant
Whats happened?

Downloaded a base box of Ubuntu, configured for
vagrant
Created a new project
  Configured to use this base box by default
Whats happened?

Downloaded a base box of Ubuntu, configured for
vagrant
Created a new project
  Configured to use this base box by default
Booted the VM: vagrant up
Whats happened?

Downloaded a base box of Ubuntu, configured for
vagrant
Created a new project
  Configured to use this base box by default
Booted the VM: vagrant up
Connected into the VM: vagrant ssh
Managing the VM
Managing the VM
Suspend
  vagrant suspend
Managing the VM
Suspend
  vagrant suspend
Resume
  vagrant resume
Managing the VM
Suspend
  vagrant suspend
Resume
  vagrant resume
Shutdown
  vagrant halt
Managing the VM
Suspend
  vagrant suspend
Resume
  vagrant resume
Shutdown
  vagrant halt
Turn on
  vagrant up (re-runs any provisioning tasks)
Lets try it
Suspend
Resume
Vagrant
Shutdown
When shit hits the fan


        vagrant destroy
Vagrant
vagrant destroy: a warning
vagrant destroy: a warning
 The VM is completely wiped
vagrant destroy: a warning
 The VM is completely wiped
 Anything that can’t be replicated from:
   Your project folder (shared folder)
   Vagrant base box
   Vagrant File
   Puppet Manifests
vagrant destroy: a warning
 The VM is completely wiped
 Anything that can’t be replicated from:
   Your project folder (shared folder)
   Vagrant base box
   Vagrant File
   Puppet Manifests
 WILL BE LOST FOREVER
   E.g. Databases (hint: use a DB patching or versioning tool in your
   project folder)
vagrant init
Creates a new Vagrantfile, which instructs
vagrant what too boot and how to do it. Let’s
take a peak.
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant::Config.run do |config|

  config.vm.box = "base"

end
Box to use

# use the box called base
config.vm.box = "base"

# Fallback URL, if we don't have a box called base, download from here
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
Networking
Networking
Host only
  VM is only visible to the host machine

  config.vm.network :hostonly, "192.168.33.10"
Networking
Host only
  VM is only visible to the host machine

  config.vm.network :hostonly, "192.168.33.10"

Bridged
  Network connection to the VM is bridged, letting it
  appear as a device on the network

  config.vm.network :bridged
Ports
Ports

Easiest way to use the VM is to forward ports
  Forwards port X on the host
  To port Y on the guest
Ports

Easiest way to use the VM is to forward ports
  Forwards port X on the host
  To port Y on the guest


config.vm.forward_port 80, 4567
Shared Folders
Shared Folders

Default:
  Current project (folder containing Vagrantfile) is
  mapped to /vagrant
Shared Folders

Default:
  Current project (folder containing Vagrantfile) is
  mapped to /vagrant
New shared folders:
  config.vm.share_folder "name", "/guestmount", "../
  hostfolder"
Provisioning



 So far: we can build and d
Provisioning with Puppet


config.vm.provision :puppet do |puppet|
    puppet.manifests_path = "provision/manifests"
    puppet.manifest_file = "default.pp"
    puppet.module_path = "provision/modules"
end
What can Puppet do
What can Puppet do
Checks conditions:
What can Puppet do
Checks conditions:
Package installed
What can Puppet do
Checks conditions:
Package installed
File exists / contains / etc
What can Puppet do
Checks conditions:
Package installed
File exists / contains / etc
Exec: Run an ad-hock command*

* doesn’t sit well with Puppets “checking” nature.
Execs get re-run (unless you use special conditions) on
vagrant up
Package


package { "apache2":
    ensure => present,
    require => Exec['apt-get update']
  }
Service

  service { "apache2":
      ensure => running,
      require => Package["apache2"]
    }
File

file   { '/etc/apache2/sites-available/default':
	 	    source => '/vagrant/provision/modules/apache/files/default',
	 	    owner => 'root',
	 	    group => 'root'
	 }
Exec

  exec { 'apt-get update':
       	command => '/usr/bin/apt-get update',
       	require => Exec['preparenetworking']
    	}
Users & Groups

   group { "wheel":
   !     ensure => "present",
   ! }
   !
   ! exec { "/bin/echo "%wheel ALL=(ALL) ALL"
   >> /etc/sudoers":
   !     require => Group["wheel"]
   ! }
Users & Groups

    user   { "developer":
    ! !    ensure => "present",
    ! !    gid => "wheel",
    ! !    shell => "/bin/bash",
    ! !    home => "/home/developer",
    ! !    managehome => true,
    ! !    password => "passwordtest",
    ! !    require => Group["wheel"]
    ! }
Stringing it together
  class apache {

      package { "apache2":
        ensure => present,
        require => Exec['apt-get update']
      }

      file { '/var/www/src':
  !       ensure => 'link',
  !       target => '/vagrant/src',
  !       require => Package['apache2']
  !    }
  !
  !    file { '/etc/apache2/sites-available/default':
  !    ! source => '/vagrant/provision/modules/apache/files/default',
  !    ! owner => 'root',
  !    ! group => 'root'
  !    }

      service { "apache2":
        ensure => running,
        require => Package["apache2"]
      }
  }
Vagrant
Using Puppet Modules


      import "apache"
      include apache
Explicit ordering



     stage { 'first': before => Stage[main] }
     class {'apache': stage => first}
Vagrant up
Vagrant
Vagrant
Multiple VMs

Within the vagrantfile, we can define multiple VMs
  E.g. need a separate VM for web and db server to
  mimic production environment?
       Vagrant::Config.run do |config|
         config.vm.define :web do |web_config|
           web_config.vm.box = "web"
           web_config.vm.forward_port 80, 8080
         end

         config.vm.define :db do |db_config|
           db_config.vm.box = "db"
           db_config.vm.forward_port 3306, 3306
         end
       end
Chef


www.opscode.com/chef
Provisioning service with Ruby based configurations
Plugins


 Backing up and snapshotting a VM
 Automated base box creators
Exporting Box

Always using the same stack / versions on your box?
Slow un-reliable Internet connection means puppet
takes an age to run? Export the base box with these
pre-installed
vagrant package
Creating your own box
Virtualbox configured:
  Guest additions
SSH & key based authentication for the vagrant user
Ruby, RubyGems, Puppet and Chef
Export the box
vagrantup.com/v1/docs/base_boxes.html
The Future



More than just VirtualBox
Caveats
Caveats
Funky permissions
  Files created on the host shared folder show without permissions on the
  guest and are inaccessible
  Solution: upgrade virtualbox guest additions on guest
Caveats
   Funky permissions
      Files created on the host shared folder show without permissions on the
      guest and are inaccessible
      Solution: upgrade virtualbox guest additions on guest
   Can’t chmod files within shared folder
config.vm.share_folder("v-root", "/vagrant", ".", :extra => 'dmode=777,fmode=777')

      Thanks @AnthonySterling & @ChrisDKemper
Caveats
   Funky permissions
      Files created on the host shared folder show without permissions on the
      guest and are inaccessible
      Solution: upgrade virtualbox guest additions on guest
   Can’t chmod files within shared folder
config.vm.share_folder("v-root", "/vagrant", ".", :extra => 'dmode=777,fmode=777')

      Thanks @AnthonySterling & @ChrisDKemper
   Waiting for VM to boot
      Open VirtualBox
      Cancel, halt the VM and try again
Caveats
   Funky permissions
      Files created on the host shared folder show without permissions on the
      guest and are inaccessible
      Solution: upgrade virtualbox guest additions on guest
   Can’t chmod files within shared folder
config.vm.share_folder("v-root", "/vagrant", ".", :extra => 'dmode=777,fmode=777')

      Thanks @AnthonySterling & @ChrisDKemper
   Waiting for VM to boot
      Open VirtualBox
      Cancel, halt the VM and try again
Conclusion

Virtualise your development environment
  Easy to add new team members
  Easy to work from other machines
  So long “works on my Machine”
Cheers!


Any questions?


@michaelpeacock
www.michaelpeacock.co.uk

More Related Content

PPTX
Vagrant crash course
PDF
Vagrant + Docker provider [+Puppet]
PDF
Vagrant for real (codemotion rome 2016)
PPTX
How To Set a Vagrant Development System
PDF
Vagrant for real codemotion (moar tips! ;-))
PDF
Vagrant for Virtualized Development
PDF
Puppet and Vagrant in development
PDF
Multi-provider Vagrant and Chef: AWS, VMware, and more
Vagrant crash course
Vagrant + Docker provider [+Puppet]
Vagrant for real (codemotion rome 2016)
How To Set a Vagrant Development System
Vagrant for real codemotion (moar tips! ;-))
Vagrant for Virtualized Development
Puppet and Vagrant in development
Multi-provider Vagrant and Chef: AWS, VMware, and more

What's hot (20)

PPTX
Vagrant + Docker
PDF
Create your very own Development Environment with Vagrant and Packer
PPTX
Vagrant
ODP
It Works On My Machine: Vagrant for Software Development
PPTX
Docker workshop
PPTX
Vagrant
PDF
Vagrant for real
PDF
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...
PPTX
Vagrant-Overview
PPTX
Vagrant to-aws-flow
PDF
Vagrant presentation
PPTX
Installaling Puppet Master and Agent
PDF
Using Docker with Puppet - PuppetConf 2014
PDF
Preparation study of_docker - (MOSG)
PDF
Instruction: dev environment
PDF
Docker puppetcamp london 2013
PDF
Vagrant and docker
PDF
EC2 AMI Factory with Chef, Berkshelf, and Packer
PDF
Puppet Camp Seattle 2014: Docker and Puppet: 1+1=3
PDF
DevOps(3) : Ansible - (MOSG)
Vagrant + Docker
Create your very own Development Environment with Vagrant and Packer
Vagrant
It Works On My Machine: Vagrant for Software Development
Docker workshop
Vagrant
Vagrant for real
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...
Vagrant-Overview
Vagrant to-aws-flow
Vagrant presentation
Installaling Puppet Master and Agent
Using Docker with Puppet - PuppetConf 2014
Preparation study of_docker - (MOSG)
Instruction: dev environment
Docker puppetcamp london 2013
Vagrant and docker
EC2 AMI Factory with Chef, Berkshelf, and Packer
Puppet Camp Seattle 2014: Docker and Puppet: 1+1=3
DevOps(3) : Ansible - (MOSG)
Ad

Viewers also liked (20)

PDF
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
PDF
Vagrant and docker
PDF
Eclipse DemoCamp Munich - Docker Tooling and Vagrant Tooling
PDF
Framework codeigniter 2
PDF
Vagrant教學
ODP
"Up" with vagrant and docker
PPTX
Vagrant and Docker
PPTX
Vagrant + ansible vs docker
PPTX
Vagrant vs Docker
PDF
Infrastructure testing with Jenkins, Puppet and Vagrant - Agile Testing Days ...
PDF
Introduction to Vagrant
PDF
Linux Container Technology inside Docker with RHEL7
PPTX
Transforming Organizations with CI/CD
PDF
Ansible is the simplest way to automate. MoldCamp, 2015
DOC
Khaleel Devops Resume (2)
DOCX
Dev ops engineer
PDF
Kubernetesを触ってみた
PDF
reveal.js 3.0.0
PDF
Ansible Introduction
PDF
How to Become a Thought Leader in Your Niche
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
Vagrant and docker
Eclipse DemoCamp Munich - Docker Tooling and Vagrant Tooling
Framework codeigniter 2
Vagrant教學
"Up" with vagrant and docker
Vagrant and Docker
Vagrant + ansible vs docker
Vagrant vs Docker
Infrastructure testing with Jenkins, Puppet and Vagrant - Agile Testing Days ...
Introduction to Vagrant
Linux Container Technology inside Docker with RHEL7
Transforming Organizations with CI/CD
Ansible is the simplest way to automate. MoldCamp, 2015
Khaleel Devops Resume (2)
Dev ops engineer
Kubernetesを触ってみた
reveal.js 3.0.0
Ansible Introduction
How to Become a Thought Leader in Your Niche
Ad

Similar to Vagrant (20)

PDF
DevOps Series: Defining and Sharing Testable Machine Configurations with vagrant
PPTX
DevOps Hackathon - Session 1: Vagrant
PDF
Making Developers Productive with Vagrant, VirtualBox, and Docker
PDF
Vagrant For DevOps
PPTX
Vagrant 101 Workshop
PDF
Create Development and Production Environments with Vagrant
PDF
Vagrant workshop 2015
PDF
Keep calm and vagrant up
PDF
Vagrant - Version control your dev environment
PDF
Virtualization with Vagrant (ua.pycon 2011)
PPT
Vagrant
PPTX
Vagrant hands on workshop for beginners
PDF
Vagrant - Team Development made easy
PDF
Intro to vagrant
PPTX
Vagrant introduction for Developers
PDF
Take Home Your Very Own Free Vagrant CFML Dev Environment
PDF
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....
PDF
Improved development workflows using vagrant
PDF
Vagrant are you still develop in a non-virtual environment-
PDF
Quick & Easy Dev Environments with Vagrant
DevOps Series: Defining and Sharing Testable Machine Configurations with vagrant
DevOps Hackathon - Session 1: Vagrant
Making Developers Productive with Vagrant, VirtualBox, and Docker
Vagrant For DevOps
Vagrant 101 Workshop
Create Development and Production Environments with Vagrant
Vagrant workshop 2015
Keep calm and vagrant up
Vagrant - Version control your dev environment
Virtualization with Vagrant (ua.pycon 2011)
Vagrant
Vagrant hands on workshop for beginners
Vagrant - Team Development made easy
Intro to vagrant
Vagrant introduction for Developers
Take Home Your Very Own Free Vagrant CFML Dev Environment
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....
Improved development workflows using vagrant
Vagrant are you still develop in a non-virtual environment-
Quick & Easy Dev Environments with Vagrant

More from Michael Peacock (20)

PPTX
Immutable Infrastructure with Packer Ansible and Terraform
PPTX
Test driven APIs with Laravel
PPTX
Symfony Workflow Component - Introductory Lightning Talk
PPTX
Alexa, lets make a skill
PPTX
API Development with Laravel
PPTX
An introduction to Laravel Passport
PDF
Phinx talk
PDF
Refactoring to symfony components
PPT
Dance for the puppet master: G6 Tech Talk
PPT
Powerful and flexible templates with Twig
PPT
Introduction to OOP with PHP
KEY
Phpne august-2012-symfony-components-friends
KEY
Evolution of a big data project
PPTX
Real time voice call integration - Confoo 2012
PPTX
Dealing with Continuous Data Processing, ConFoo 2012
PPTX
Data at Scale - Michael Peacock, Cloud Connect 2012
PPTX
Supermondays twilio
PPTX
PHP & Twilio
PPTX
PHP Continuous Data Processing
PPTX
PHP North East Registry Pattern
Immutable Infrastructure with Packer Ansible and Terraform
Test driven APIs with Laravel
Symfony Workflow Component - Introductory Lightning Talk
Alexa, lets make a skill
API Development with Laravel
An introduction to Laravel Passport
Phinx talk
Refactoring to symfony components
Dance for the puppet master: G6 Tech Talk
Powerful and flexible templates with Twig
Introduction to OOP with PHP
Phpne august-2012-symfony-components-friends
Evolution of a big data project
Real time voice call integration - Confoo 2012
Dealing with Continuous Data Processing, ConFoo 2012
Data at Scale - Michael Peacock, Cloud Connect 2012
Supermondays twilio
PHP & Twilio
PHP Continuous Data Processing
PHP North East Registry Pattern

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPT
Teaching material agriculture food technology
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Encapsulation theory and applications.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
cuic standard and advanced reporting.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Empathic Computing: Creating Shared Understanding
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Electronic commerce courselecture one. Pdf
NewMind AI Monthly Chronicles - July 2025
Building Integrated photovoltaic BIPV_UPV.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Chapter 3 Spatial Domain Image Processing.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Teaching material agriculture food technology
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Reach Out and Touch Someone: Haptics and Empathic Computing
Encapsulation theory and applications.pdf
Machine learning based COVID-19 study performance prediction
cuic standard and advanced reporting.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
“AI and Expert System Decision Support & Business Intelligence Systems”
Empathic Computing: Creating Shared Understanding
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

Vagrant

  • 1. Vagrant: virtualise your development environment Michael Peacock August 2012, SuperMondays
  • 2. About Me @michaelpeacock Head Developer @ Ground Six Leading the development team and managing the development process We are a tech investment company: you bring ideas, we partner and build the product Author Occasional Speaker
  • 5. Virtualisation Abstraction layer for your hardware Lets multiple Operating Systems run concurrently, each running on their own virtual hardware
  • 6. Virtualisation Abstraction layer for your hardware Lets multiple Operating Systems run concurrently, each running on their own virtual hardware Limited by your own physical hardware and your host machine
  • 10. VirtualBox www.virtualbox.org Virtualisation software tool Provides the hardware abstraction layer and an interface for running VMs
  • 12. Vagrant www.vagrantup.com “Create and configure lightweight, reproducable, and portable development environments”
  • 13. Vagrant www.vagrantup.com “Create and configure lightweight, reproducable, and portable development environments” Set of command line tools which interacts with and automates VirtualBox
  • 14. Vagrant www.vagrantup.com “Create and configure lightweight, reproducable, and portable development environments” Set of command line tools which interacts with and automates VirtualBox Designed around portability
  • 16. Why?
  • 17. Why? Quick start time for new team members Vagrant up: you have a development environment
  • 18. Why? Quick start time for new team members Vagrant up: you have a development environment Server configuration can be version controlled
  • 19. Why? Quick start time for new team members Vagrant up: you have a development environment Server configuration can be version controlled Cross-platform: work from any machine
  • 20. Why? Quick start time for new team members Vagrant up: you have a development environment Server configuration can be version controlled Cross-platform: work from any machine Work on multiple projects? Easy to pickup an old, legacy project with its funky server configs
  • 21. Why? Quick start time for new team members Vagrant up: you have a development environment Server configuration can be version controlled Cross-platform: work from any machine Work on multiple projects? Easy to pickup an old, legacy project with its funky server configs Can run multiple VMs independently
  • 22. Why? Quick start time for new team members Vagrant up: you have a development environment Server configuration can be version controlled Cross-platform: work from any machine Work on multiple projects? Easy to pickup an old, legacy project with its funky server configs Can run multiple VMs independently Doesn’t mess with your local, host machine
  • 24. Some terms Host: Your physical machine
  • 25. Some terms Host: Your physical machine Guest: The VM
  • 29. Overview 1.Project specific configuration file 2.Import base box 3.Boot up Virtual Machine 1.Forward Ports 2.Share folders
  • 30. Overview 1.Project specific configuration file 2.Import base box 3.Boot up Virtual Machine 1.Forward Ports 2.Share folders 4.Configure / provision software
  • 31. 3 lines: up and running
  • 32. 3 lines: up and running # download a “base” VM image and give it the name # base for future use vagrant box add base http://files.vagrantup.com/ precise64.box # Initialise a new vagrant project # i.e. create a new vagrant file vagrant init # Boot the VM based off the config file we created vagrant up
  • 33. 3 lines: up and running # download a “base” VM image and give it the name # base for future use vagrant box add base http://files.vagrantup.com/ precise64.box # Initialise a new vagrant project # i.e. create a new vagrant file vagrant init # Boot the VM based off the config file we created vagrant up
  • 34. 3 lines: up and running # download a “base” VM image and give it the name # base for future use vagrant box add base http://files.vagrantup.com/ precise64.box # Initialise a new vagrant project # i.e. create a new vagrant file vagrant init # Boot the VM based off the config file we created vagrant up
  • 35. 3 lines: up and running # download a “base” VM image and give it the name # base for future use vagrant box add base http://files.vagrantup.com/ precise64.box # Initialise a new vagrant project # i.e. create a new vagrant file vagrant init # Boot the VM based off the config file we created vagrant up
  • 36. 3 lines: up and running # download a “base” VM image and give it the name # base for future use vagrant box add base http://files.vagrantup.com/ precise64.box # Initialise a new vagrant project # i.e. create a new vagrant file vagrant init # Boot the VM based off the config file we created vagrant up
  • 37. 3 lines: up and running # download a “base” VM image and give it the name # base for future use vagrant box add base http://files.vagrantup.com/ precise64.box # Initialise a new vagrant project # i.e. create a new vagrant file vagrant init # Boot the VM based off the config file we created vagrant up
  • 38. 3 lines: up and running # download a “base” VM image and give it the name # base for future use vagrant box add base http://files.vagrantup.com/ precise64.box # Initialise a new vagrant project # i.e. create a new vagrant file vagrant init # Boot the VM based off the config file we created vagrant up
  • 39. 3 lines: up and running # download a “base” VM image and give it the name # base for future use vagrant box add base http://files.vagrantup.com/ precise64.box # Initialise a new vagrant project # i.e. create a new vagrant file vagrant init # Boot the VM based off the config file we created vagrant up
  • 40. 3 lines: up and running # download a “base” VM image and give it the name # base for future use vagrant box add base http://files.vagrantup.com/ precise64.box # Initialise a new vagrant project # i.e. create a new vagrant file vagrant init # Boot the VM based off the config file we created vagrant up
  • 41. 3 lines: up and running # download a “base” VM image and give it the name # base for future use vagrant box add base http://files.vagrantup.com/ precise64.box # Initialise a new vagrant project # i.e. create a new vagrant file vagrant init # Boot the VM based off the config file we created vagrant up
  • 42. 3 lines: up and running # download a “base” VM image and give it the name # base for future use vagrant box add base http://files.vagrantup.com/ precise64.box # Initialise a new vagrant project # i.e. create a new vagrant file vagrant init # Boot the VM based off the config file we created vagrant up
  • 48. SSH into the box vagrant ssh
  • 50. Whats happened? Downloaded a base box of Ubuntu, configured for vagrant
  • 51. Whats happened? Downloaded a base box of Ubuntu, configured for vagrant Created a new project Configured to use this base box by default
  • 52. Whats happened? Downloaded a base box of Ubuntu, configured for vagrant Created a new project Configured to use this base box by default Booted the VM: vagrant up
  • 53. Whats happened? Downloaded a base box of Ubuntu, configured for vagrant Created a new project Configured to use this base box by default Booted the VM: vagrant up Connected into the VM: vagrant ssh
  • 55. Managing the VM Suspend vagrant suspend
  • 56. Managing the VM Suspend vagrant suspend Resume vagrant resume
  • 57. Managing the VM Suspend vagrant suspend Resume vagrant resume Shutdown vagrant halt
  • 58. Managing the VM Suspend vagrant suspend Resume vagrant resume Shutdown vagrant halt Turn on vagrant up (re-runs any provisioning tasks)
  • 64. When shit hits the fan vagrant destroy
  • 67. vagrant destroy: a warning The VM is completely wiped
  • 68. vagrant destroy: a warning The VM is completely wiped Anything that can’t be replicated from: Your project folder (shared folder) Vagrant base box Vagrant File Puppet Manifests
  • 69. vagrant destroy: a warning The VM is completely wiped Anything that can’t be replicated from: Your project folder (shared folder) Vagrant base box Vagrant File Puppet Manifests WILL BE LOST FOREVER E.g. Databases (hint: use a DB patching or versioning tool in your project folder)
  • 70. vagrant init Creates a new Vagrantfile, which instructs vagrant what too boot and how to do it. Let’s take a peak.
  • 71. # -*- mode: ruby -*- # vi: set ft=ruby : Vagrant::Config.run do |config| config.vm.box = "base" end
  • 72. Box to use # use the box called base config.vm.box = "base" # Fallback URL, if we don't have a box called base, download from here config.vm.box_url = "http://files.vagrantup.com/precise64.box"
  • 74. Networking Host only VM is only visible to the host machine config.vm.network :hostonly, "192.168.33.10"
  • 75. Networking Host only VM is only visible to the host machine config.vm.network :hostonly, "192.168.33.10" Bridged Network connection to the VM is bridged, letting it appear as a device on the network config.vm.network :bridged
  • 76. Ports
  • 77. Ports Easiest way to use the VM is to forward ports Forwards port X on the host To port Y on the guest
  • 78. Ports Easiest way to use the VM is to forward ports Forwards port X on the host To port Y on the guest config.vm.forward_port 80, 4567
  • 80. Shared Folders Default: Current project (folder containing Vagrantfile) is mapped to /vagrant
  • 81. Shared Folders Default: Current project (folder containing Vagrantfile) is mapped to /vagrant New shared folders: config.vm.share_folder "name", "/guestmount", "../ hostfolder"
  • 82. Provisioning So far: we can build and d
  • 83. Provisioning with Puppet config.vm.provision :puppet do |puppet| puppet.manifests_path = "provision/manifests" puppet.manifest_file = "default.pp" puppet.module_path = "provision/modules" end
  • 85. What can Puppet do Checks conditions:
  • 86. What can Puppet do Checks conditions: Package installed
  • 87. What can Puppet do Checks conditions: Package installed File exists / contains / etc
  • 88. What can Puppet do Checks conditions: Package installed File exists / contains / etc Exec: Run an ad-hock command* * doesn’t sit well with Puppets “checking” nature. Execs get re-run (unless you use special conditions) on vagrant up
  • 89. Package package { "apache2": ensure => present, require => Exec['apt-get update'] }
  • 90. Service service { "apache2": ensure => running, require => Package["apache2"] }
  • 91. File file { '/etc/apache2/sites-available/default': source => '/vagrant/provision/modules/apache/files/default', owner => 'root', group => 'root' }
  • 92. Exec exec { 'apt-get update': command => '/usr/bin/apt-get update', require => Exec['preparenetworking'] }
  • 93. Users & Groups group { "wheel": ! ensure => "present", ! } ! ! exec { "/bin/echo "%wheel ALL=(ALL) ALL" >> /etc/sudoers": ! require => Group["wheel"] ! }
  • 94. Users & Groups user { "developer": ! ! ensure => "present", ! ! gid => "wheel", ! ! shell => "/bin/bash", ! ! home => "/home/developer", ! ! managehome => true, ! ! password => "passwordtest", ! ! require => Group["wheel"] ! }
  • 95. Stringing it together class apache { package { "apache2": ensure => present, require => Exec['apt-get update'] } file { '/var/www/src': ! ensure => 'link', ! target => '/vagrant/src', ! require => Package['apache2'] ! } ! ! file { '/etc/apache2/sites-available/default': ! ! source => '/vagrant/provision/modules/apache/files/default', ! ! owner => 'root', ! ! group => 'root' ! } service { "apache2": ensure => running, require => Package["apache2"] } }
  • 97. Using Puppet Modules import "apache" include apache
  • 98. Explicit ordering stage { 'first': before => Stage[main] } class {'apache': stage => first}
  • 102. Multiple VMs Within the vagrantfile, we can define multiple VMs E.g. need a separate VM for web and db server to mimic production environment? Vagrant::Config.run do |config| config.vm.define :web do |web_config| web_config.vm.box = "web" web_config.vm.forward_port 80, 8080 end config.vm.define :db do |db_config| db_config.vm.box = "db" db_config.vm.forward_port 3306, 3306 end end
  • 104. Plugins Backing up and snapshotting a VM Automated base box creators
  • 105. Exporting Box Always using the same stack / versions on your box? Slow un-reliable Internet connection means puppet takes an age to run? Export the base box with these pre-installed vagrant package
  • 106. Creating your own box Virtualbox configured: Guest additions SSH & key based authentication for the vagrant user Ruby, RubyGems, Puppet and Chef Export the box vagrantup.com/v1/docs/base_boxes.html
  • 107. The Future More than just VirtualBox
  • 109. Caveats Funky permissions Files created on the host shared folder show without permissions on the guest and are inaccessible Solution: upgrade virtualbox guest additions on guest
  • 110. Caveats Funky permissions Files created on the host shared folder show without permissions on the guest and are inaccessible Solution: upgrade virtualbox guest additions on guest Can’t chmod files within shared folder config.vm.share_folder("v-root", "/vagrant", ".", :extra => 'dmode=777,fmode=777') Thanks @AnthonySterling & @ChrisDKemper
  • 111. Caveats Funky permissions Files created on the host shared folder show without permissions on the guest and are inaccessible Solution: upgrade virtualbox guest additions on guest Can’t chmod files within shared folder config.vm.share_folder("v-root", "/vagrant", ".", :extra => 'dmode=777,fmode=777') Thanks @AnthonySterling & @ChrisDKemper Waiting for VM to boot Open VirtualBox Cancel, halt the VM and try again
  • 112. Caveats Funky permissions Files created on the host shared folder show without permissions on the guest and are inaccessible Solution: upgrade virtualbox guest additions on guest Can’t chmod files within shared folder config.vm.share_folder("v-root", "/vagrant", ".", :extra => 'dmode=777,fmode=777') Thanks @AnthonySterling & @ChrisDKemper Waiting for VM to boot Open VirtualBox Cancel, halt the VM and try again
  • 113. Conclusion Virtualise your development environment Easy to add new team members Easy to work from other machines So long “works on my Machine”

Editor's Notes