Slide 1

Slide 1 text

Cloud your Laptop with Vagrant http://www.flickr.com/photos/taoquay/8317906849/

Slide 2

Slide 2 text

I am Evgeny I do DevOps for a living (for many years in many places) Currently at Devops Israel www.devops.co.il

Slide 3

Slide 3 text

$ git clone github.com:my-company/my-product $ ???????? $ rackup Server listening on port 3000 Your Product today http://www.flickr.com/photos/wreckthisgirl/6627729785/

Slide 4

Slide 4 text

http://www.flickr.com/photos/morinkovo_fotky/4168850871/ Problem(s)

Slide 5

Slide 5 text

http://www.flickr.com/photos/tafkabecky/2801101874/ ... when you did not refactor A complex system.

Slide 6

Slide 6 text

... when you build a team Onboarding is hard and time consuming. http://www.flickr.com/photos/mortenhammer/2973926090/

Slide 7

Slide 7 text

... when you have a product Environments inconsistency. dev vs. qa vs. ci vs. stage vs. prod vs. client’s server

Slide 8

Slide 8 text

http://www.flickr.com/photos/newscale/3860725378/ ... when you have a production A dedicated Server Guy.

Slide 9

Slide 9 text

... when you have lots of time Repeat my steps, manually. http://www.flickr.com/photos/mrfrosted/278847814/

Slide 10

Slide 10 text

... when you do it every week Deploy on Thursdays! http://www.flickr.com/photos/shanecasey51/5029929897/

Slide 11

Slide 11 text

... when your boss is not looking Deploy script refactoring. http://www.flickr.com/photos/prairiechick/1326500270/

Slide 12

Slide 12 text

http://www.flickr.com/photos/kaibabnationalforest/4438630647/ ... when your customers call Troubleshoot it in production.

Slide 13

Slide 13 text

Familiar? http://www.flickr.com/photos/71072750@N00/5647840760/

Slide 14

Slide 14 text

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/

Slide 15

Slide 15 text

✓ 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/

Slide 16

Slide 16 text

VirtualBox www.virtualbox.org Innotek GmbH 2007 Sun Microsystems 2008 Oracle 2010

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

Vagrant’s author Mitchell Hashimoto https://medium.com/brief-interviews/2a19b5e1c770

Slide 19

Slide 19 text

A solution for VirtualBox automation complexity. Vagrant www.vagrantup.com

Slide 20

Slide 20 text

“ Talk is cheap. Show me the code ” - Linus Torvalds http://www.flickr.com/photos/joberrr/399140205/

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

$ 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/

Slide 23

Slide 23 text

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}/

Slide 24

Slide 24 text

# 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

Slide 25

Slide 25 text

# 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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

$ 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

Slide 28

Slide 28 text

Vagrantfile provision with shell I_CAN_HAS_CHEF=<

Slide 29

Slide 29 text

Vagrantfile provision with shell I_CAN_HAS_PUPPET=<

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

$ 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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

$ 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

Slide 37

Slide 37 text

http://www.flickr.com/photos/drachmann/327122302/

Slide 38

Slide 38 text

advanced tips’n’tricks http://www.flickr.com/photos/peosoldier/4777978052/

Slide 39

Slide 39 text

$ 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

Slide 40

Slide 40 text

$ 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

Slide 41

Slide 41 text

$ 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

Slide 42

Slide 42 text

unethicalblogger.com/2012/03/13/introducing-the-vagrant-plugin.html github.com/rtyler/vagrant-plugin testing (with) vagrant jenkins plugin

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

$ 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

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

http://www.flickr.com/photos/wwworks/4759535950/ take these slides offline at bit.ly/vagrant-cloud-laptop