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

Vagrant - Cloud your Laptop

Vagrant - Cloud your Laptop

How vagrant can help development teams save time, be more consistent across environments have a working ruby/python/php environment without putting much effort into it each and every time.

Learn what vagrant is offering, overview of features and problems it solves. Start making your development and production available with a push of a button instead of wasted hours and days.

Evgeny Zislis

January 28, 2013
Tweet

Other Decks in Technology

Transcript

  1. I am Evgeny I do DevOps for a living (for

    many years in many places) Currently at Devops Israel www.devops.co.il
  2. $ git clone github.com:my-company/my-product $ ???????? $ rackup Server listening

    on port 3000 Your Product today http://www.flickr.com/photos/wreckthisgirl/6627729785/
  3. ... when you build a team Onboarding is hard and

    time consuming. http://www.flickr.com/photos/mortenhammer/2973926090/
  4. ... when you have a product Environments inconsistency. dev vs.

    qa vs. ci vs. stage vs. prod vs. client’s server
  5. ... when you have lots of time Repeat my steps,

    manually. http://www.flickr.com/photos/mrfrosted/278847814/
  6. ... when you do it every week Deploy on Thursdays!

    http://www.flickr.com/photos/shanecasey51/5029929897/
  7. ... when your boss is not looking Deploy script refactoring.

    http://www.flickr.com/photos/prairiechick/1326500270/
  8. Imagine the product running on hardware and software which directly

    matches your production deployment, on your laptop. On your first day on the job. "The Cloud" on your computer http://www.flickr.com/photos/21644167@N04/3897234326/
  9. ✓ Scalable ✓ Isolated ✓ Consistent ✓ Repeatable ✓ Cost

    efficient ✓ Fast onboarding ✓ ... Server guy not needed Virtual Machines the solution to all problems http://www.flickr.com/photos/hubmedia/2141860216/
  10. VirtualBox www.virtualbox.org x86 and AMD64/Intel64 virtualization GPLv2 Windows, Linux, OS

    X & Solaris 320 page User Manual Automatable - API + CLI after you read the manual
  11. “ Talk is cheap. Show me the code ” -

    Linus Torvalds http://www.flickr.com/photos/joberrr/399140205/
  12. $ gem install vagrant Installing archive-tar-minitar (0.5.2) Installing ffi (1.3.1)

    with native extensions Installing childprocess (0.3.7) Installing erubis (2.7.0) Installing i18n (0.6.1) Installing json (1.5.4) with native extensions Installing log4r (1.1.10) Installing net-ssh (2.2.2) Installing net-scp (1.0.4) Installing vagrant (1.0.6) installing vagrant or via downloads.vagrantup.com PS: VirtualBox should already be installed.
  13. $ vagrant init quantal http://bit.ly/vagrant-quantal A `Vagrantfile` has been placed

    in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant. $ vagrant up [default] Box quantal was not found. Fetching box from specified URL... [vagrant] Downloading with Vagrant::Downloaders::HTTP... [vagrant] Downloading box: http://bit.ly/vagrant-quantal [vagrant] Downloading box: http://cloud.ubuntu.com/vagrant/.../quantal64.box [vagrant] Progress: 3% (12394751 / 366284800) ... [default] Booting VM... [default] Waiting for VM to boot. This can take a few minutes. [default] VM booted and ready for use! ... using vagrant PS: Vagrant’s documentation is excellent! http://docs.vagrantup.com/
  14. vagrant box where to get them? http://cloud-images.ubuntu.com/vagrant/ http://vagrantbox.es/ # https://github.com/garethr/vagrantboxes-heroku

    http://my-company.s3.amazonaws.com/my-bucket/my-box. box $ vagrant box add quantal http://bit.ly/vagrant-quantal # saved in ~/.vagrant.d/boxes/{box_name}/
  15. # install or update VirtualBox guest additions automatically $ gem

    install vagrant-vbguest # github.com/dotless-de/vagrant-vbguest Vagrant::Config.run do |c| c.vm.box = "quantal" c.vm.box_url = "http://bit.ly/vagrant-quantal" end Vagrantfile which box to use
  16. # add or update /etc/hosts on "vagrant up" $ gem

    install vagrant-hostmaster # github.com/mosaicxm/vagrant-hostmaster Vagrant::Config.run do |c| c.vm.host_name = "dev-server.vagrant.local" # gem vagrant-hostmaster c.hosts.aliases = "dev-server" c.vm.forward_port 80, 8080 c.vm.network :hostonly, "192.168.33.10" c.vm.network :bridged end Vagrantfile networking
  17. Vagrant::Config.run do |c| c.vm.customize [ "modifyvm", :id, "--memory", 2048] c.vm.customize

    [ "modifyvm", :id, "--cpus", 4] end # what it actually does before "vagrant up" is: $ VBoxManage modifyvm your_box_id --memory 2048 # See docs http://www.virtualbox.org/manual/ch08.html Vagrantfile virtualbox settings
  18. $ gem install vagrant-persistent-storage # github.com/kusnier/vagrant-persistent-storage Vagrant::Config.run do |c| c.vm.share_folder

    "v-root", "/vagrant", ".", nfs: true c.vm.customize [ "setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", 1 ] # gem vagrant-persistent-storage c.persistent_storage.location = "~/dev/pkgs.vdi" c.persistent_storage.size = 5000 end # require "ffi" # share_folder ..., :nfs => (FFI::Platform::IS_WINDOWS ? false : true) # shared /var/cache/apt $ gem install vagrant-apt_cache # github.com/avit/vagrant-apt_cache Vagrantfile mount disks
  19. Vagrantfile provision with shell I_CAN_HAS_CHEF=<<EOF #!/bin/sh [ -d /opt/chef ]

    && exit 0 curl -s -L https://www.opscode.com/chef/install.sh | bash EOF Vagrant::Config.run do |c| # ... c.vm.provision :shell, inline: I_CAN_HAS_CHEF end
  20. Vagrantfile provision with shell I_CAN_HAS_PUPPET=<<EOF #!/bin/sh codename=`lsb_release -c -s` [

    ! -d /etc/apt ] && { echo "Only works on Debian/Ubuntu Linux!"; exit 1; } cd /tmp [ -f puppetlabs-release-$codename.deb ] && exit 0 curl -s -L -O http://apt.puppetlabs.com/puppetlabs-release-$codename.deb && \ dpkg -i puppetlabs-release-$codename.deb && \ apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y puppet EOF Vagrant::Config.run do |c| # ... c.vm.provision :shell, inline: I_CAN_HAS_PUPPET end
  21. Vagrantfile provision with chef-solo Vagrant::Config.run do |c| # ... c.vm.provision

    :chef_solo do |chef| chef.cookbooks_path = "cookbooks" chef.data_bags_path = "databags" chef.add_recipe "bootstrap_my_chef_server" chef.json = { password: "verysecret" } end end
  22. $ gem install vagrant-butcher # github.com/cassianoleal/vagrant-butcher # `vagrant destroy` now

    removes guest’s "client" & "node" on the chef server Vagrant::Config.run do |c| # ... c.vm.provision :chef_client do |chef| chef.chef_server_url = "http://chef.vagrant.local" end end Vagrantfile provision with a chef server
  23. Vagrantfile provision with puppet apply Vagrant::Config.run do |c| c.vm.provision :puppet

    do |puppet| puppet.manifests_path = "manifests" puppet.module_path = "modules" puppet.manifest_file = "site.pp" puppet.options = ["--onetime", "--no-daemonize"] # puppet.options = ["--verbose", "--debug"] end end
  24. Vagrantfile provision with puppet apply $ gem install vagrant-puppetconf #

    github.com/gposton/vagrant-puppetconf # modify /etc/puppet/puppet.conf via command line and vagrantfile Vagrant::Config.run do |c| c.vm.provision :puppet_server do |puppet| puppet.puppet_server = "puppet.vagrant.local" # puppet.options = ["--verbose", "--debug"] end # w/gem vagrant-puppetconf c.puppetconf.updates = { "main/environment" => "test" } end
  25. Vagrantfile provision with Ruby $ gem install vagrant-hostruby # github.com/chrisberkhout/vagrant-hostruby

    Vagrant::Config.run do |c| c.vm.provision :hostruby, provision: lambda do |env| File.delete "/tmp/xyz" if File.exists? "/tmp/xyz" # ... more ruby code end end
  26. Vagrantfile multiple virtual machines - multi-vm Vagrant::Config.run do |c| c.vm.box

    = "quantal" c.vm.define :web do |vm| # ... vm.customize [ "modifyvm", :id, "--name", "web"] end c.vm.define :db do |vm| # ... vm.customize [ "modifyvm", :id, "--name", "db"] end end
  27. $ vagrant up - boot + provision $ vagrant provision

    - only provision $ vagrant halt - ssh box "shutdown -h now" $ vagrant reload - halt + up $ vagrant ssh - ssh box $ vagrant suspend - pause (virtual) box $ vagrant destroy $ vagrant --help vagrant commands
  28. $ gem install vagrant-kick # github.com/arioch/vagrant-kick # github.com/mconigliaro/vagrant-test $ cat

    tests/node01.local check_http -H node01.vagrant.local -p 80 $ cat tests/node01.ssh uptime $ vagrant kick [node01] REMOTE [node01] uptime [node01] 23:47:27 up 2:36, 0 users, load average: 0.00, 0.00, 0.00 [node01] LOCAL [node01] check_http -H node01.vagrant.local -p 80 CRITICAL - Socket timeout after 10 seconds testing (with) vagrant vagrant-kick / vagrant-test
  29. $ gem install vagabond # github.com/wfarr/vagabond describe file("/etc/motd") do it

    { should exist } it { should have_content /welcome to zombocom/ } end describe service("nginx") do it { should be_running } it { should respond_on(8080) } end testing (with) vagrant vagabond
  30. $ gem install vagrant-prison require "vagrant/prison" prison = Vagrant::Config.new prison.configure

    do |config| config.vm.box = "ubuntu" config.vm.define :test, primary: true do |c| c.vm.network :hostonly, "192.168.33.10" end end prison.start testing (with) vagrant vagrant-prison
  31. spawn environments with ease and rake $ cap deploy vagrant

    $ cap deploy production $ cap deploy ec2-dev-evgeny $ rake launch:vagrant,postgresql $ rake launch:ec2,dev $ rake destroy:production,riak-001 $ rake provision:staging,haproxy-002
  32. vagrant box how to create them? $ vagrant package -

    or - # spilth.org/blog/2013/01/21/automated-vm-generation-with-veewee-jenkins-and-amazon-s3/ $ gem install veewee $ veewee vbox define my-linux archlinux-x86_64 $ veewee vbox build my-linux
  33. $ VBoxManage list vms "dev_xyz" {c077a8a9-9965-487c-bfd0-95574804671f} # start a vm

    and record its screen output $ VBoxHeadless --startvm "dev_xyz" --capture -f "out.mp4" # use vagrant’s default key in your ssh agent # default passwords are root:vagrant & vagrant:vagrant $ ssh-add ~/.vagrant.d/insecure_private_key Fixed bugs! https://github.com/mitchellh/vagrant/pulls VirtualBox & Vagrant tips’n’tricks
  34. more gems the interesting ones virtualbox API for VirtualBox (also)

    by Mitchell # github.com/mitchellh/virtualbox vagrant-rake execute "rake" commands inside the guest without ssh # github.com/mitchellh/vagrant-rake vagrant-screenshot debug with screen shots # github.com/igorsobreira/vagrant-screenshot vagrant-serial serial port forwarding # github.com/7Pikes/vagrant-serial vagrant-snap create/delete/use snapshots # github.com/t9md/vagrant-snap vagrant-sync rsync files from host to guest # github.com/calavera/vagrant-sync vagrant-aws & mccloud provision boxes in the cloud not VirtualBox # github.com/mlinderm/vagrant-aw # github.com/jedi4ever/mccloud vagrant-multi-putty / vagrant-putty use "vagrant putty" instead of "vagrant ssh" # github.com/nickryand/vagrant-multi-putty vagrant-plugins manage plugins in vagrant 1.1 (not released yet) # github.com/dotless-de/vagrant-plugins