Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Virtualization with Vagrant (ua.pycon 2011)


Published on

Presentation on topic of using virtualized environment in development and testing, especially for web applications.

Prepared for Pycon Ukraine 2011

Published in: Technology
  • Be the first to comment

Virtualization with Vagrant (ua.pycon 2011)

  1. 1. Virtual testing &development** batteries included
  2. 2. $ git clone git://$ runIdeal world
  3. 3. $ git clone git:// world
  4. 4. $ git clone git:// read help$ mkdir, cp, vim config.conf, configure, make, makeinstall... ask guru$ /project/hidden/blackmagic --fix_that --fix_this --undocumented_parameter=MAGIC_CONST_42... %^ing @#$@#%@!!!!Real world
  5. 5. $ git clone git:// read help$ mkdir, cp, vim config.conf, configure, make, makeinstall... ask guru$ /project/hidden/blackmagic --fix_that --fix_this --undocumented_parameter=MAGIC_CONST_42... %^ing @#$@#%@!!!!$ runReal world
  6. 6. Why?
  7. 7. Operating SystemUser SpaceMusicWebServerDBAppServerIMEditorBrowser
  8. 8. Problems• No isolation (oh, wrong binary onpath...?)• Not repeatable (that README ain’tgonna run itself!)• No guarantees (“..but it works on mycomputer!”)
  9. 9. Solution?
  10. 10. Operating SystemMusicWebServer DBAppServerIM EditorBrowserUser SpaceVirtualized OS
  11. 11. Benefits• Isolation (project and version specificfiles only)• Repeatable (snapshots, copies,automation)• Guarantees (same OS different day)
  12. 12. Business benefits• Reduce costs (less hardware, lower energyconsumption)• Backup and data protection• Application availability• Less time to respond to changing businessneeds• Less time spent on routine tasks• Better IT department perception
  13. 13. Time spend on routine tasksaccording to VMware small & medium business survey
  14. 14. Why haven’t we been doingthis for a long time?• Big companies have been• Amazon EC2• Microsoft• Google• Only recently possible on local machines• Cheat hardware• Cheap RAM• Desktop virtualization API
  15. 15. Ok, let’s go virtual.Now what?
  16. 16. Vagrant is a tool for building anddistributing virtualized developmentenvironments (
  17. 17. VirtualBox is cross-platform virtualization softwarethat works on all the major platforms(
  18. 18. High level overview• Describe environment with Vagrantfiles• Command line interface to manage VM lifecycle• Automate provisioning and configuration• Share folder with host OS via NFS• Provide SSH access to guest OS• Network multiple VMs• Package and distribute VMs
  19. 19. Vagrant boxes• Box = pre-packaged VM environment (~OSimage)• A number of ready to use boxes @• Ubuntu 32 / 64• CentOS• Solaris• RH
  20. 20. Vagrantfile• Vagrantfile is to Vagrant as Makefile is toMake• Describes VM in code• One Vagrantfile per project (can containmultiple VMs)• Commit it to version control• Actually a Ruby code - easy to extent
  21. 21. do |config| = “base_ubuntu"end
  22. 22. Command line$ vagrant helpvagrant initvagrant upvagrant haltvagrant reloadvagrant suspendvagrant resumevagrant destroyvagrant provisionvagrant package…
  23. 23. • Isolation (project and versionspecific files only)• Repeatable (snapshots, copies,automation)• Guarantees (same OS different day)
  24. 24. Chef is an open-source systemsintegration framework built specificallyfor automating the cloud (
  25. 25. Puppet is a system for automatingsystem administration tasks, workson most UNIX-like operatingsystems (
  26. 26. How Chef/Puppet works• You create recipes• Recipes describe desired system state• Then you manage your server park• Safely• Repeatedly• In automated way
  27. 27. Provisioning in Vagrant• Use Chef, Puppet, bash scripts, etc. tomanage VM configuration• Repeatable!• Use same tools for production - Chef,Puppet
  28. 28. Vagrant + do |config| = “base_ubuntu_box"config.vm.provision :chef_solo do |chef|chef.recipe_url = "http://server/cookbooks.tar.gz"chef.add_recipe(“aptitude")chef.add_recipe(“apache2")chef.add_recipe(“mysql-server")chef.add_recipe(“python27")chef.add_recipe(“pip")endend
  29. 29. Networking• Assign IP to VM in Vagrantfile• Forward ports• Access VM from your browser
  30. 30. do |config| = "lucid32""")config.vm.forward_port("web", 80, 4567)end
  31. 31. • Isolation (project and versionspecific files only)• Repeatable (snapshots, copies,automation)• Guarantees (same OS different day)
  32. 32. Packaging• When environment is stable• Package and distribute prepared VMs• Minimize setup time
  33. 33. • Isolation (project and versionspecific files only)• Repeatable (snapshots, copies,automation)• Guarantees (same OS different day)
  34. 34. Beyond that• Multi-VM Vagrantfile• DB• AppServer• WebServer• Use vagrant as library• Call API functions to do the tasks fromRuby code• Run custom SSH commands
  35. 35. Demo
  36. 36.•Django application•Apache2 + MySQL on single VM•Additional Python packages like used (South, annoying)•DB migrations handled by South•Deployment process• Vagrant is used to create VM, install required packages andconfigure services• Fabric ( is used to populate DB, set up apache2 confand install Python modules
  37. 37. Prerequisites$ <install python>$ <install ruby>$ <install virtualbox>$ gem install vagrant$ git clone http://server/project.git$ cd project
  38. 38. Demo: create VM, deploy project00:00:00 $ vagrant box add base http://server/ base box for VM is copied to your computer00:02:00 $ vagrant up... vagrant creates VM from base box, installs and configuresrequired packages – apt, apache2, mysql, python, git, …00:05:00 $ fab deploy... DB is populated with initial data, apache config updated, apacherestarted00:07:00 $ curl http://localhost:8080/... site is up and running.
  39. 39. Real world
  40. 40. Our experience• 10+ projects during last 18 months• From small (single webserver, no DB) tomedium (several webservers + load balancer,master/slave DB replication)• New developer start time reduced from 2-3days to 1 hr on average• Number of deployment/environment defectsreduced by 75%
  41. 41. Links•••••••
  42. 42. Dmitry Guyvoronsky