Using Vagrant

14,384 views

Published on

Using Vagrant for VM management, development environments and dev/prod parity.

1 Comment
17 Likes
Statistics
Notes
No Downloads
Views
Total views
14,384
On SlideShare
0
From Embeds
0
Number of Embeds
180
Actions
Shares
0
Downloads
0
Comments
1
Likes
17
Embeds 0
No embeds

No notes for slide
  • \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
  • Using Vagrant

    1. 1. Using Vagrant Andy Gale
    2. 2. Who are you? Andy Gale andy-gale.com @andygale
    3. 3. What is Vagrant?va·grant/ˈvāgrənt/Noun:A person without a settled home orregular work who wanders from placeto place and lives by begging.
    4. 4. What is Vagrant?A way of managing virtual machines • Run different operating systems • Define virtual machines in code • Save your own ass
    5. 5. Why Vagrant? 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 a day• Produces unpredictable results
    6. 6. Why Vagrant?Your development and production environment are not the same!• Different OS?• Different version of PHP/Python/Ruby?• Diverged package versions?• Different default configuration files?
    7. 7. Why Vagrant?• 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!
    8. 8. Why Vagrant?• 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
    9. 9. Vagrant sounds good!
    10. 10. Getting Started• Install Oracle’s VirtualBox www.virtualbox.org/wiki/Downloads• Install Vagrant (packages for Windows, Mac, Linux) downloads.vagrantup.com
    11. 11. Getting Started Create a$ vagrant box add precise32http://files.vagrantup.com/precise32.box Intialise a workspace$ cd workspace$ vagrant init precise32
    12. 12. Configuration• Simple to configure using the Vagrantfile - A Ruby DSL - 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
    13. 13. Configuration Define shared folderconfig.vm.share_folder "v-data", "/data", "../data" Static IP config.vm.network 192.168.0.100 Set hostname config.vm.host_name = "steve" Boot with GUI config.vm.boot_mode :gui
    14. 14. Vagrant Defaults• /vagrant - shares your workspace• Default username "vagrant"• Default password "vagrant"
    15. 15. Multiple VMsVagrant::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  endend
    16. 16. It’s alive! Bring box up! $ vagrant upConnection to box $ vagrant ssh Close down box $ vagrant halt Delete box$ vagrant destroy
    17. 17. So what else?• Install all the packages you need once• Make it the same as your product environment• Make a base box and distribute amongst developers• What time has this actually saved
    18. 18. Package$ vagrant package --vagrantfile
    19. 19. ProvisionersYou can provision with:• Shell• Chef Solo• Chef Server• Puppet• Puppet Server• Build your own
    20. 20. Provisioners ShellVagrant::Config.run do |config|  config.vm.provision :shell, :path =>"test.sh"end
    21. 21. Provisioners Chef Solo:Vagrant::Config.run do |config|  config.vm.provision :chef_solo do |chef|    chef.roles_path = "roles"    chef.add_role("vm")  endend
    22. 22. Provisioners Chef Server:Vagrant::Config.run do |config|  config.vm.provision :chef_server do |chef|     chef.chef_server_url = "http://chef.inter.net"     chef.add_role("vm")  endend
    23. 23. Provisioners Puppet:Vagrant::Config.run do |config|  config.vm.provision :puppet do |puppet|     puppet.mainfests_path ="puppetmanifests"     puppet.mainfest_file = "newbox.pp"  endend
    24. 24. Provisioners Puppet Server:Vagrant::Config.run do |config|  config.vm.provision :puppet_server do |puppet|     puppet.puppet_server ="puppet.inter.net"     puppet.puppet_node ="vm.internet.net"  endend
    25. 25. Provision with Chef• A tool for automating the provisioning and management of your servers• Open source• Lots of examples and code to get you started
    26. 26. Chef Very brief overview CookbooksCollections of recipes, templates and otherconfiguration attributes to get stuff done. RecipesChunks of Ruby code that describe what stuff we need to do to get that stuff done.
    27. 27. Chef My First Recipe Install packagepackage "ntp" do  action :installend Create config file from templatetemplate "/etc/ntp.conf" do  source "ntp.conf.erb"  owner "root" Restart service  group "root" when config file  mode 0644 changes  notifies :restart, resources(:service => "ntp")endservice "ntp" do  action :start Define service andend start NTP
    28. 28. Chef Scary but you’re not alone• Community cookbooks http://community.opscode.com/• IRC #chef on freenode• Foodfight show podcast http://foodfightshow.org/index.html• Ask me andygale@andy-gale.com
    29. 29. Example Get started with a CakePHP application environment with Vagrant and Chef • Install Oracle’s VirtualBox • Install Vagrant$ git clone git@github.com:salgo/cakefest-vagrant-chef.git$ cd cakefest-vagrant-chef$ ./git-fetch-submodules.sh$ vagrant up
    30. 30. Vagrant and onwards Will soon support new virtualisers• OpenStack• VMWare?• Linux containers?• Write your own?
    31. 31. Vagrant Tips• If you’re running OS X make sure OS updates are compatible with VirtualBox - Oracle are quick to release fixes but best to check• Keep guest additions up to date with https://github.com/dotless-de/vagrant-vbguest• You can play with Chef in Vagrant so there’s no excuse not to try
    32. 32. 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 Bithttp://files.vagrantup.com/precise32.box Ubuntu Precise 64 Bithttp://files.vagrantup.com/precise64.box
    33. 33. Other Boxes Example boxes here
    34. 34. Questions?

    ×