1. Get Started
    1. Overview
      1. Install Vagrant
        1. $ gem install vagrant $ gem list vagrant -d
        2. $ git clone git://github.com/mitchellh/vagrant.git $ bundle install $ bundle show vagrant
      2. Your First Vagrant Virtual Environment
        1. $ vagrant box add lucid32 http://files.vagrantup.com/lucid32.box $ vagrant init lucid32 $ vagrant up
    2. Why Vagrant?
      1. Web developers use virtual environments every day with their web applications.
      2. By providing easy to configure, lightweight, reproducible, and portable virtual machines targeted at development environments, Vagrant helps maximize your productivity and flexibility.
      3. Vagrant is a development tool which stands on the shoulders of giants, using tried and proven technologies to achieve its magic.
      4. Vagrant uses Oracle’s VirtualBox to create its virtual machines and then uses Chef or Puppet to provision them.
      5. For Solo Developers
        1. Each project depends on its own libraries, message queue systems, databases, framework, and more, each with their own versions.
      6. For Teams
        1. Vagrant gives teams the ability to enforce a consistent and portable virtual development environment that is easy to create and quick to setup.
      7. For Companies
    3. Introduction
      1. binaries
        1. help
        2. version
        3. status
        4. box
          1. list
          2. add/remove
          3. repackage
        5. init/destroy
          1. vagrant init [box_name] [box_url]
        6. up/halt
        7. reload
        8. suspend/resume
        9. ssh/ssh_config
        10. package
        11. provision
      2. Vagrantfile
        1. Vagrant::Config.run do |config| ... end
          1. config.vm.box = "my_box"
    4. Project Setup
      1. $ mkdir vagrant_guide $ cd vagrant_guide $ vagrant init # using box "base"
    5. Boxes
      1. ~/.vagrant.d/boxes
      2. Getting a Base Box
        1. $ vagrant box add lucid32 http://files.vagrantup.com/lucid32.box
      3. Removing Boxes
        1. $ vagrant box remove my_box
      4. Configuring the Project to use the Box
        1. Subcommand init
          1. $ vagrant init [box_name] [URL]
        2. Vagrantfile
          1. config.vm.box = "lucid32"
    6. SSH
      1. Nothing beats the power of the command line.
      2. $ vagrant ssh
      3. Accessing the Project Files
        1. Default directory "/vagrant" on guest
        2. config.vm.share_folder "v-data", "/vagrant_data", "../data"
    7. Provisioning
      1. chef
        1. config.vm.provision :chef_solo do |chef| chef.recipe_url = "http://files.vagrantup.com/getting_started/cookbooks.tar.gz" chef.add_recipe("vagrant_main") end
    8. Port Forwarding
      1. config.vm.forward_port("web", 80, 4567)
      2. $ vagrant reload
    9. Packaging
      1. Vagrantfile.pkg
        1. Vagrant::Config.run do |config| # Forward apache config.vm.forward_port("web", 80, 8080) end
      2. $ vagrant package --vagrantfile Vagrantfile.pkg
      3. What's with the MAC address?
    10. Teardown
      1. $ vagrant suspend
      2. $ vagrant halt
      3. $ vagrant destroy
      4. LE
        1. pros and cons
    11. Rebuild Instantly
      1. $ cd project_dir $ vagrant up # BINGO
  2. Documentation
    1. Commands
      1. $ vagrant
        1. help
          1. COMMAND
        2. version
          1. $ be bin/vagrant version Vagrant version 0.8.7.dev
        3. box
          1. add
          2. NAME URI
          3. help
          4. $ be bin/vagrant box help Tasks: vagrant box add NAME URI # Add a box to the system vagrant box help [COMMAND] # Describe subcommands or one specific subcommand vagrant box list # Lists all installed boxes vagrant box remove NAME # Remove a box from the system vagrant box repackage NAME # Repackage an installed box into a `.box` file.
          5. list
          6. remove
          7. NAME
          8. repackage
          9. NAME
        4. package
          1. --vagrantfile
          2. --vagrantfile Vagrantfile.pkg
          3. --include
          4. --include README.txt
        5. init
        6. status
        7. up
          1. Requires Vagrantfile
          2. Build the VM based on the box
          3. Setup shared folders
          4. Setup forwarded ports
          5. Provision with chef or Puppet (if configured)
          6. Boot in the background
        8. reload
        9. resume
        10. suspend
        11. halt
        12. destroy
        13. provision
        14. ssh
        15. ssh-config
          1. $ vagrant ssh-config Host vagrant HostName localhost User vagrant Port 2222 UserKnownHostsFile /dev/null StrictHostKeyChecking no IdentityFile /opt/local/lib/ruby/gems/1.8/gems/vagrant-0.3.0/keys/vagrant
          2. $ scp vagrant:/vagrant/my_file.txt ~/Desktop/my_file.txt
    2. Vagrantfile
      1. Load Order
        1. Vagrantfile from the gem directory
          1. ~/.rvm/gems/`rvm current`/gems/vagrant-0.8.6/config/default.rb
        2. Vagrantfile from the box directory
          1. ~/.vagrant.d/boxes/base/Varantfile
          2. ~/.vagrant.d/boxes/base/include/_Vagrantfile
        3. Vagrantfile from the home directory
          1. ~/.vagrant.d/Vagrantfile
        4. Vagrantfile from the project directory
          1. ./Vagrantfile
      2. Structure
        1. Vagrant::Config.run do |config| config.xxx.yyy.zzz = "..." end
      3. Options
        1. config
          1. vm
          2. box
          3. "base"
          4. "my_box"
          5. box_url
          6. "http://some.url.for/some_remote_box.box"
          7. "/some/local/path/to/a.box"
          8. customize
          9. structure
          10. config.vm.customize do |vm| vm.xxx = XXX vm.yyy = "YYY" end
          11. memory_size
          12. name
          13. forward_port
          14. "web", 80, 8080
          15. "ftp", 21, 4567
          16. "ssh", 22, 2222, :auto => true
          17. network
          18. web_config.vm.network("192.168.1.10")
          19. db_config.vm.network("192.168.1.11")
          20. share_folder
          21. "v-root", "/vagrant", ".", :nfs => true
          22. "my-folder", "/folder", "/path/to/real/folder"
          23. "another-folder", "/other", "../other"
          24. "third-folder", "/third", ".", :owner => "my-user", :group => "my-group"
          25. define
          26. Vagrant::Config.run do |config| config.vm.define :web do |web_config| web_config.vm.box = "web" web_config.vm.forward_port("http", 80, 8080) end config.vm.define :db do |db_config| db_config.vm.box = "db" db_config.vm.forward_port("db", 3306, 3306) end end
          27. provision
          28. provision
          29. config.vm.provision :chef_solo
          30. config.vm.provision :chef_solo, :cookbooks_path => "cookbooks", :run_list => "recipe[foo]"
          31. config.vm.provision :chef_solo do |chef| chef.cookbooks_path = "cookbooks" chef.add_recipe "foo" end
          32. box_ovf
          33. "box.ovf"
          34. base_mac
          35. "0800274153F3"
          36. useful for those creating boxes for distribution
          37. chef
          38. recipe_url
          39. "http://files.vagrantup.com/getting_started/cookbooks.tar.gz"
          40. cookbooks_path
          41. chef.cookbooks_path = "cookbooks"
          42. chef.cookbooks_path = ["cookbooks", "~/company/cookbooks"]
          43. chef.cookbooks_path = [:vm, "cookbooks"]
          44. chef.cookbooks_path = ["local-cookbooks", [:vm, "cookbooks"]]
          45. add_recipe
          46. chef.add_recipe "foo"
          47. roles_path
          48. chef.roles_path = "roles"
          49. add_role
          50. chef.add_role("web")
          51. json
          52. config.chef.json = { :instance_role => "vagrant", :recipes => ["vagrant_main"] }
          53. config.chef.json.merge!({ :mysql => { :server_root_password => "my_root_password" } })
          54. can be used to set attributes for the cookbooks used in provisioning
          55. provisioning_path
          56. chef.provisioning_path = "/tmp/vagrant-chef"
          57. run_list
          58. # Accessing the run list directly config.chef.run_list = ["recipe[foo]", "recipe[bar]"]
          59. # Using the helpers config.chef.add_recipe("foo") config.chef.add_role("bar")
          60. provisioning_path
          61. chef.provisioning_path = "/tmp/vagrant-chef"
          62. package
          63. name
          64. extension
    3. Provisioners
      1. chef
      2. puppet
      3. shell
        1. config.vm.provision :shell, :inline => "echo foo > /vagrant/test"
        2. $ cat test.sh #!/bin/bash echo Hello, World! $ cat Vagrantfile ... config.vm.provision :shell, :path => "test.sh" ...
        3. config.vm.provision :shell do |shell| shell.inline = "echo $1 > /vagrant/test" shell.args = "'write this to a file'" end