$30 off During Our Annual Pro Sale. View Details »

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. Love thy vagrant
    DrupcalCamp Vienna 2013
    Sebastian Göttschkes

    View Slide

  2. 3 reasons

    View Slide

  3. 3 reasons

    View Slide

  4. 3 reasons
    http://simply-the-test.blogspot.co.at/2010/05/it-works-on-my-machine.html

    View Slide

  5. 3 reasons

    View Slide

  6. @Sgoettschkes
    # music
    # bodymod
    # symfony
    # agile
    # devops

    View Slide

  7. Wogibtswas

    View Slide

  8. 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

    View Slide

  9. The dark times

    View Slide

  10. The dark times
    Word, Outlook, “nice” GUI
    “Compatible with work” Host
    Sourcecode, IDE, Stack
    “Development” VM

    View Slide

  11. The dark times
    Sourcecode, IDE
    localhost
    Synced Folder
    Apache, PHP,
    MYSQL
    Remote VM
    Sync Sourcecode
    Run commands

    View Slide

  12. The dark cloud times

    View Slide

  13. Enter vagrant

    View Slide

  14. 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

    View Slide

  15. 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

    View Slide

  16. 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

    View Slide

  17. 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

    View Slide

  18. Providers

    View Slide

  19. 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

    View Slide

  20. 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

    View Slide

  21. Shell Provisioning
    Vagrant.configure("2") do |config|
    # …
    config.vm.provision "shell", inline: $script
    config.vm.provision “shell”, path: "provision.sh"
    end
    $script = <apt-get update
    apt-get install -y python-software-properties
    SCRIPT

    View Slide

  22. 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

    View Slide

  23. 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

    View Slide

  24. Puppet Provisioning
    package { nginx:
    ensure => installed
    }
    file { "/etc/nginx/nginx.conf":
    source => "nginx.conf"
    }
    exec { "install mongo from pecl":
    command => 'pecl install -f mongo',
    }

    View Slide

  25. 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!

    View Slide

  26. 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

    View Slide

  27. Real world vagrant
    vs

    View Slide

  28. 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

    View Slide

  29. 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

    View Slide

  30. Real world vagrant

    View Slide

  31. Real world vagrant
    Yet
    Another
    Tool?

    View Slide

  32. 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?

    View Slide

  33. 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?

    View Slide