• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Vagrant
 

Vagrant

on

  • 1,810 views

 

Statistics

Views

Total Views
1,810
Views on SlideShare
1,804
Embed Views
6

Actions

Likes
4
Downloads
54
Comments
0

1 Embed 6

http://lanyrd.com 6

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Vagrant Vagrant Presentation Transcript

  • Vagrant: virtualise yourdevelopment environmentMichael PeacockAugust 2012, SuperMondays
  • About Me @michaelpeacockHead Developer @ Ground SixLeading the development team and managing thedevelopment processWe are a tech investment company: you bring ideas, wepartner and build the productAuthorOccasional 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
  • Vagrantwww.vagrantup.com “Create and configure lightweight, reproducable, and portable development environments”
  • Vagrantwww.vagrantup.com “Create and configure lightweight, reproducable, and portable development environments”Set of command line tools which interacts with andautomates VirtualBox
  • Vagrantwww.vagrantup.com “Create and configure lightweight, reproducable, and portable development environments”Set of command line tools which interacts with andautomates VirtualBoxDesigned around portability
  • PuppetProvisioning 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 environmentServer configuration can be version controlled
  • Why?Quick start time for new team members Vagrant up: you have a development environmentServer configuration can be version controlledCross-platform: work from any machine
  • Why?Quick start time for new team members Vagrant up: you have a development environmentServer configuration can be version controlledCross-platform: work from any machineWork on multiple projects? Easy to pickup an old, legacyproject with its funky server configs
  • Why?Quick start time for new team members Vagrant up: you have a development environmentServer configuration can be version controlledCross-platform: work from any machineWork on multiple projects? Easy to pickup an old, legacyproject with its funky server configsCan run multiple VMs independently
  • Why?Quick start time for new team members Vagrant up: you have a development environmentServer configuration can be version controlledCross-platform: work from any machineWork on multiple projects? Easy to pickup an old, legacyproject with its funky server configsCan run multiple VMs independentlyDoesn’t mess with your local, host machine
  • Some terms
  • Some termsHost: Your physical machine
  • Some termsHost: Your physical machineGuest: The VM
  • Overview
  • Overview1.Project specific configuration file
  • Overview1.Project specific configuration file2.Import base box
  • Overview1.Project specific configuration file2.Import base box3.Boot up Virtual Machine 1.Forward Ports 2.Share folders
  • Overview1.Project specific configuration file2.Import base box3.Boot up Virtual Machine 1.Forward Ports 2.Share folders4.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 usevagrant box add base http://files.vagrantup.com/precise64.box# Initialise a new vagrant project# i.e. create a new vagrant filevagrant init# Boot the VM based off the config file we createdvagrant up
  • 3 lines: up and running # download a “base” VM image and give it the name# base for future usevagrant box add base http://files.vagrantup.com/precise64.box# Initialise a new vagrant project# i.e. create a new vagrant filevagrant init# Boot the VM based off the config file we createdvagrant up
  • 3 lines: up and running # download a “base” VM image and give it the name# base for future usevagrant box add base http://files.vagrantup.com/precise64.box# Initialise a new vagrant project# i.e. create a new vagrant filevagrant init# Boot the VM based off the config file we createdvagrant up
  • 3 lines: up and running # download a “base” VM image and give it the name# base for future usevagrant box add base http://files.vagrantup.com/precise64.box# Initialise a new vagrant project# i.e. create a new vagrant filevagrant init# Boot the VM based off the config file we createdvagrant up
  • 3 lines: up and running # download a “base” VM image and give it the name# base for future usevagrant box add base http://files.vagrantup.com/precise64.box# Initialise a new vagrant project# i.e. create a new vagrant filevagrant init# Boot the VM based off the config file we createdvagrant up
  • 3 lines: up and running # download a “base” VM image and give it the name# base for future usevagrant box add base http://files.vagrantup.com/precise64.box# Initialise a new vagrant project# i.e. create a new vagrant filevagrant init# Boot the VM based off the config file we createdvagrant up
  • 3 lines: up and running # download a “base” VM image and give it the name# base for future usevagrant box add base http://files.vagrantup.com/precise64.box# Initialise a new vagrant project# i.e. create a new vagrant filevagrant init# Boot the VM based off the config file we createdvagrant up
  • 3 lines: up and running # download a “base” VM image and give it the name# base for future usevagrant box add base http://files.vagrantup.com/precise64.box# Initialise a new vagrant project# i.e. create a new vagrant filevagrant init# Boot the VM based off the config file we createdvagrant up
  • 3 lines: up and running # download a “base” VM image and give it the name# base for future usevagrant box add base http://files.vagrantup.com/precise64.box# Initialise a new vagrant project# i.e. create a new vagrant filevagrant init# Boot the VM based off the config file we createdvagrant up
  • 3 lines: up and running # download a “base” VM image and give it the name# base for future usevagrant box add base http://files.vagrantup.com/precise64.box# Initialise a new vagrant project# i.e. create a new vagrant filevagrant init# Boot the VM based off the config file we createdvagrant up
  • 3 lines: up and running # download a “base” VM image and give it the name# base for future usevagrant box add base http://files.vagrantup.com/precise64.box# Initialise a new vagrant project# i.e. create a new vagrant filevagrant init# Boot the VM based off the config file we createdvagrant up
  • Let’s try it...
  • SSH into the boxvagrant ssh
  • Whats happened?
  • Whats happened?Downloaded a base box of Ubuntu, configured forvagrant
  • Whats happened?Downloaded a base box of Ubuntu, configured forvagrantCreated a new project Configured to use this base box by default
  • Whats happened?Downloaded a base box of Ubuntu, configured forvagrantCreated a new project Configured to use this base box by defaultBooted the VM: vagrant up
  • Whats happened?Downloaded a base box of Ubuntu, configured forvagrantCreated a new project Configured to use this base box by defaultBooted the VM: vagrant upConnected into the VM: vagrant ssh
  • Managing the VM
  • Managing the VMSuspend vagrant suspend
  • Managing the VMSuspend vagrant suspendResume vagrant resume
  • Managing the VMSuspend vagrant suspendResume vagrant resumeShutdown vagrant halt
  • Managing the VMSuspend vagrant suspendResume vagrant resumeShutdown vagrant haltTurn on vagrant up (re-runs any provisioning tasks)
  • Lets try it
  • Suspend
  • Resume
  • Shutdown
  • When shit hits the fan vagrant destroy
  • 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 initCreates a new Vagrantfile, which instructsvagrant what too boot and how to do it. Let’stake 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 baseconfig.vm.box = "base"# Fallback URL, if we dont have a box called base, download from hereconfig.vm.box_url = "http://files.vagrantup.com/precise64.box"
  • Networking
  • NetworkingHost only VM is only visible to the host machine config.vm.network :hostonly, "192.168.33.10"
  • NetworkingHost 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
  • PortsEasiest way to use the VM is to forward ports Forwards port X on the host To port Y on the guest
  • PortsEasiest way to use the VM is to forward ports Forwards port X on the host To port Y on the guestconfig.vm.forward_port 80, 4567
  • Shared Folders
  • Shared FoldersDefault: Current project (folder containing Vagrantfile) is mapped to /vagrant
  • Shared FoldersDefault: Current project (folder containing Vagrantfile) is mapped to /vagrantNew shared folders: config.vm.share_folder "name", "/guestmount", "../ hostfolder"
  • Provisioning So far: we can build and d
  • Provisioning with Puppetconfig.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 doChecks conditions:
  • What can Puppet doChecks conditions:Package installed
  • What can Puppet doChecks conditions:Package installedFile exists / contains / etc
  • What can Puppet doChecks conditions:Package installedFile exists / contains / etcExec: Run an ad-hock command** doesn’t sit well with Puppets “checking” nature.Execs get re-run (unless you use special conditions) onvagrant up
  • Packagepackage { "apache2": ensure => present, require => Exec[apt-get update] }
  • Service service { "apache2": ensure => running, require => Package["apache2"] }
  • Filefile { /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"] } }
  • Using Puppet Modules import "apache" include apache
  • Explicit ordering stage { first: before => Stage[main] } class {apache: stage => first}
  • Vagrant up
  • Multiple VMsWithin 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
  • Chefwww.opscode.com/chefProvisioning service with Ruby based configurations
  • Plugins Backing up and snapshotting a VM Automated base box creators
  • Exporting BoxAlways using the same stack / versions on your box?Slow un-reliable Internet connection means puppettakes an age to run? Export the base box with thesepre-installedvagrant package
  • Creating your own boxVirtualbox configured: Guest additionsSSH & key based authentication for the vagrant userRuby, RubyGems, Puppet and ChefExport the boxvagrantup.com/v1/docs/base_boxes.html
  • The FutureMore than just VirtualBox
  • Caveats
  • CaveatsFunky 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 folderconfig.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 folderconfig.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 folderconfig.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
  • ConclusionVirtualise your development environment Easy to add new team members Easy to work from other machines So long “works on my Machine”
  • Cheers!Any questions?@michaelpeacockwww.michaelpeacock.co.uk