Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Love thy vagrant

Sebastian
November 22, 2013

Love thy vagrant

An introduction to vagrant for DrupalCamp 2013. Aimed at beginners, in this talk I talk about providers, provisioners and plugins. I also cover best practices and address problems which vagrant may introduce.

Sebastian

November 22, 2013
Tweet

More Decks by Sebastian

Other Decks in Programming

Transcript

  1. Coming up • What vagrant really is • How you

    can start using vagrant today (or tomorrow if you don’t want to miss the other awesome talks) • Some neat tricks • The downside of vagrant
  2. The dark times Word, Outlook, “nice” GUI “Compatible with work”

    Host Sourcecode, IDE, Stack “Development” VM
  3. The dark times Sourcecode, IDE localhost Synced Folder Apache, PHP,

    MYSQL Remote VM Sync Sourcecode Run commands
  4. Enter vagrant • Configuration: Vagrantfile • Boxes: Exported Virtual Machines

    + metadata • Providers: VirtualBox • Synced folders: Folders from the host which are dublicated inside the VM • Provisioners: Shell / ansible / Chef / Puppet • Plugins: Way to extend Vagrant with additional Providers, Provisioners and other stuff
  5. The Vagrantfile Vagrant.configure("2") do |config| config.vm.network "private_network", ip: "10.61.6.2" config.vm.hostname

    = "drupal" config.vm.box = "precise64" config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.synced_folder "../project", "/var/www/project" config.vm.provision shell, inline: "sudo apt-get update" end
  6. Configuration Vagrant.configure("2") do |config| config.vm.network "private_network", ip: "10.61.6.2" config.vm.hostname =

    "drupal" config.vm.box = "precise64" config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.synced_folder "../project", "/var/www/project" config.vm.provision shell, inline: "sudo apt-get update" end
  7. The boxes Vagrant.configure("2") do |config| config.vm.network "private_network", ip: "10.61.6.2" config.vm.hostname

    = "drupal" config.vm.box = "precise64" config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.synced_folder "../project", "/var/www/project" config.vm.provision shell, inline: "sudo apt-get update" end
  8. Synced folders Vagrant.configure("2") do |config| config.vm.network "private_network", ip: "10.61.6.2" config.vm.hostname

    = "drupal" config.vm.box = "precise64" config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.synced_folder "../project", "/var/www/project" config.vm.provision shell, inline: "sudo apt-get update" end
  9. Provisioning Vagrant.configure("2") do |config| config.vm.network "private_network", ip: "10.61.6.2" config.vm.hostname =

    "drupal" config.vm.box = "precise64" config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.synced_folder "../project", "/var/www/project" config.vm.provision shell, inline: "sudo apt-get update" end
  10. Shell Provisioning Vagrant.configure("2") do |config| # … config.vm.provision "shell", inline:

    $script config.vm.provision “shell”, path: "provision.sh" end $script = <<SCRIPT apt-get update apt-get install -y python-software-properties SCRIPT
  11. Ansible Provisioning --- tasks: - name: Install nginx apt: pkg=nginx

    state=latest - name: Copy nginx config copy: src=nginx.conf dest=/etc/nginx/nginx.conf - name: Install mongodb pecl module command: pecl install -f mongo
  12. Chef Provisioning package "nginx" do action :install end template "/etc/nginx/nginx.conf"

    do source "nginx.conf.erb" action :create end execute "pecl install -f mongo" do action :run end
  13. Puppet Provisioning package { nginx: ensure => installed } file

    { "/etc/nginx/nginx.conf": source => "nginx.conf" } exec { "install mongo from pecl": command => 'pecl install -f mongo', }
  14. Plugins # AWS provider $ vagrant plugin install vagrant-aws #

    Boxen provisioner $ vagrant plugin install ventriloquist # Manage host files $ vagrant plugin install vagrant-hostmanager # Make screenshots of your VM $ vagrant plugin install vagrant-camera # … many more!
  15. A sample workflow Repository Vagrantfile Provisiong files … $ git

    clone [email protected]:vagrantLover/awesomeVm.git $ cd awesomeVm $ vagrant up # this may take a while $ vagrant ssh
  16. Real world vagrant apache php python ruby nodejs mysql mongodb

    redis project1 project2 python-stuff crazy-idea vs apache php mysql apache php mongodb redis apache php nodejs mysql project1 project2 project3
  17. Real world vagrant Ubuntu box #1 Ubuntu box #3 Ubuntu

    box #2 Ubuntu box #4 Ubuntu box #5 Debian box #1 Debian box #2 Debian box #3 Arch box #1 Arch box #2 vs Ubuntu base box Debian base box Arch base box
  18. Real world vagrant Which provider? Which base box? Which provisioner?

    How should I start? How to best solve X? Do I need many vms? How should I switch? What if anything goes wrong?
  19. Real world vagrant Which provider? Which base box? Which provisioner?

    How should I start? How to best solve X? Do I need many vms? How should I switch? What if anything goes wrong? Would you start already?