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

Getting Started with Vagrant

Getting Started with Vagrant

Part one of a split talk on Vagrant. Slightly updated version of my previous talk Using Vagrant.

Andy Gale

March 18, 2013
Tweet

More Decks by Andy Gale

Other Decks in Technology

Transcript

  1. Getting Started with Vagrant Andy Gale Tuesday, 19 March 13

  2. Who are you? Andy Gale Head of Technology Content Hub

    Ltd @andygale Tuesday, 19 March 13
  3. A way of managing virtual machines • Run different operating

    systems • Define virtual machines in code • Save your own ass What is Vagrant? Tuesday, 19 March 13
  4. Vagrant Who has tried Vagrant before? Tuesday, 19 March 13

  5. Setting up a development environment • Often considered a right

    of passage • Takes hours, often requires support • Requires documentation that’s always frequently out of date • Breaking your development environment can kill productivity for days • Produces unpredictable results Why Vagrant? Tuesday, 19 March 13
  6. Your development and production environment are not the same! •

    Different OS? • Different version of PHP/Python/Ruby? • Diverged package versions? • Different default configuration files? Why Vagrant? Tuesday, 19 March 13
  7. • Update a website with a new feature. • The

    feature relies on a PHP module that is required by your web app • Module already installed on your laptop because another project that is hosted elsewhere needed it • It’s not a the server you deploy to, so the entire website stops working • You have no idea why, the same code worked on your machine • It worked on my machine! Why Vagrant? Tuesday, 19 March 13
  8. • Vagrant configuration should be stored in version control •

    New developers can start developing quicker • Switch between projects, versions of PHP, languages with a few commands Why Vagrant? Tuesday, 19 March 13
  9. • Vagrant lowers development environment setup time • Maximizes dev/prod

    parity • Makes the “works on my machine” excuse a relic of the past. from vagrantup.com Why Vagrant? Tuesday, 19 March 13
  10. Vagrant sounds good! Tuesday, 19 March 13

  11. • Install Oracle’s VirtualBox www.virtualbox.org/wiki/Downloads • Install Vagrant (packages for

    Windows, Mac, Linux) downloads.vagrantup.com Getting Started Tuesday, 19 March 13
  12. Box • A box is a saved image of virtual

    machine that contains all the necessary packages to use Vagrant • You can make your own from an existing VirtualBox VM or use one of the official Vagrant boxes Tuesday, 19 March 13
  13. Official Boxes Ubuntu Lucid 32 Bit http://files.vagrantup.com/lucid32.box Ubuntu Lucid 64

    Bit http://files.vagrantup.com/lucid64.box Ubuntu Precise 32 Bit http://files.vagrantup.com/precise32.box Ubuntu Precise 64 Bit http://files.vagrantup.com/precise64.box Tuesday, 19 March 13
  14. More Boxes Example boxes here Tuesday, 19 March 13

  15. Getting Started $ vagrant box add precise32 http://files.vagrantup.com/precise32.box Create a

    box Intialise a workspace $ cd workspace $ vagrant init precise32 Tuesday, 19 March 13
  16. Configuration • Simple to configure using the Vagrantfile a text

    file which can be kept in version control • Easy to forward ports: Vagrant::Config.run do |config| # Forward guest port 80 to # host port 4567 config.vm.forward_port 80, 4567 end Tuesday, 19 March 13
  17. Configuration config.vm.share_folder "v-data", "/data", "../data" Define shared folder Static IP

    config.vm.network '192.168.0.100' Set hostname config.vm.host_name = "steve" Boot with GUI config.vm.boot_mode :gui Tuesday, 19 March 13
  18. Multiple VMs 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 Tuesday, 19 March 13
  19. Vagrant Commands Create and start box $ vagrant up Connect

    to box $ vagrant ssh Close down box $ vagrant halt Delete box $ vagrant destroy Tuesday, 19 March 13
  20. Vagrant Defaults • /vagrant - shares your workspace • Default

    username "vagrant" • Default password "vagrant" Tuesday, 19 March 13
  21. • VirtualBox • Amazon EC2 • Rackspace • VMware Fusion

    (costs $79 per seat) • (more to come from the community) Providers Not just VirtualBox!!! Tuesday, 19 March 13
  22. • Shell • Chef Solo • Chef Server • Puppet

    • Puppet Server • Build your own Provisioners You can provision with: Tuesday, 19 March 13