Vagrant

4,863 views

Published on

Many of us deploy to systems which are completely different from the systems we develop on, and can be difficult to set up particularly if there are a lot of moving pieces in your setup. These could be things like message queuing systems, various databases or specific versions of scripting languages such as ruby. This makes it a very time intensive process to bring new people up to speed on your projects, and to get systems set up right the first time. What if you could have a system that would launch a virtual environment, provision and run all of your systems's various components, be repeatable and fit on a thumb drive? Vagrant allows this by putting a ruby DSL on top of Oracle's VirtualBox API. It allows you to set up and provision your servers using Chef or Puppet, and to reuse those scripts on your real production environment if you want. This makes your server infrastructure version controlled just like your application code. We will go through a setup of a Vagrant instance and show how using shared folders you can develop locally, but be developing on your "local cloud", your running Vagrant instance.

Published in: Technology, Self Improvement
0 Comments
15 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,863
On SlideShare
0
From Embeds
0
Number of Embeds
95
Actions
Shares
0
Downloads
166
Comments
0
Likes
15
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • works on my machine is not a valid response\n\n
  • \n
  • \n
  • \n
  • shared folders - map a directory in your working directory to a place on the virtual file system\nuses share folders of vb by default, can use NFS if you have lots of files\nSSH access - can ssh to it from anywhere if you export and use the \n
  • vagrant boxes download to ~./vagrant/boxes\ndownload once, is base for other vagrant projects, each project leaves box unmodified\n\n
  • vagrant boxes download to ~./vagrant/boxes\ndownload once, is base for other vagrant projects, each project leaves box unmodified\n\nLucid32 is a Unbuntu 10.04 image\nother boxes look to vagrantbox.es\n
  • explain what a vagrantfile is\nlike a rails generator\n
  • imports base box HD into VB\noptionally it wil provision if its enabled\n\n
  • \n
  • ssh to box\nls /vagrant\ncreate a file on local\nshow it\nshow that its running inside of VB\nvagrant destroy\nmapping how it works\npossible to use NFS, some people say default sharing works not so well on big files\n\n
  • explain\ninterestingly no rename\n\n
  • not sure who said this, Zed Shaw perhaps\n
  • by default vagrant provisioning is disabled\n\n
  • you can do chef.json = in new build (chef only)\nmost examples are chef only, problem because its like italian/spanish.. similar but not same\n
  • \n
  • \n
  • \n
  • \n
  • Cookbooks bundle recipes that describe how you want a part of your server to be configured along with the assets they need, such as configuration files or templates.\n
  • \n
  • \n
  • \n
  • \n
  • use blink tag\n\n
  • use TM\n
  • vagrant reload if you have changed the cookbook path\n
  • \n
  • creates a package.box\n
  • creates a file package.box in the same directory\nShoot for less than 500MB, otherwise too unwiedly, use tips on vagrantup.com\nDefault Memory Allocation set to 360MB\n
  • \n
  • Vagrant

    1. 1. VagrantBuilding Virtual Development Environments With Vagrant
    2. 2. VagrantBuilding Virtual Development Environments With Vagrant
    3. 3. VagrantBuilding Virtual Development Environments With Vagrant Stop Cutting Cords!
    4. 4. Mike Hagedorn• @mwhagedorn• mike@silverchairsolutions.com
    5. 5. Vagrant Agenda• Why Vagrant?• Vagrant Hello World• Provisioning and Vagrant• Sample Rails App• Other cool stuff
    6. 6. $ git clone git://.../website.git$ rails s In a perfect world...
    7. 7. $ git clone git://.../website.git$ ...$ (magic occurs)$ ...$ rails s On my planet...
    8. 8. $ git clone git://.../website.git$ ...$ (magic occurs) Huh?$ ...$ rails s On my planet...
    9. 9. The Issues• No Isolation• Not Repeatable• Not Reliable
    10. 10. The Solution• Virtualization!
    11. 11. Resolved Issues• Isolation • Application Code Silo’ed• Repeatable • Server Configuration Is Controlled• Reliable • Server Configuration is Proven
    12. 12. Other Benefits• Bring New People Up To Speed FAST!• Server Configuration is Source Controlled• Easier What-If scenarios With Your System
    13. 13. Vagrant• By Mitch Hashimoto and John Bender (1/2010 first commit)• Leverages Virtual Box • Free Virtualization Solution from Oracle• Provisioning via Chef or Puppet • Others via extension API• Shared Folders• SSH Access
    14. 14. Installation$ gem install vagrant$ vagrant box add base http://files.vagrantup.com/lucid32.box$ vagrant init$ vagrant up
    15. 15. Installation$ gem install vagrant$ vagrant box add base http://files.vagrantup.com/lucid32.box$ vagrant init$ vagrant up Downloads, saves as ‘base’ (other distros vagrantboxes.es)
    16. 16. Installation$ gem install vagrant$ vagrant box add base http://files.vagrantup.com/lucid32.box$ vagrant init$ vagrant up Create Vagrantfile
    17. 17. Installation$ gem install vagrant$ vagrant box add base http://files.vagrantup.com/lucid32.box$ vagrant init$ vagrant up Launches Instance
    18. 18. VagrantfileVagrant::Config.run do |config| config.vm.box = "base"end
    19. 19. Demo
    20. 20. Other Commands$ vagrant box list$ vagrant box remove <NAME>$ vagrant up | halt #launch/shutdown$ vagrant destroy #shutdown and delete image$ vagrant suspend | resume #pause and restart
    21. 21. Provisioning“Logging In To The Server Is A Smell”
    22. 22. Vagrant & Provisioners
    23. 23. Customizing ProvisionersVagrant::Config.run do |config| config.vm.box = "lucid32" config.vm.forward_port ‘web’, 80,4567 # Enable and configure the chef solo provisioner config.vm.provision :chef_solo do |chef| # Were going to use a local copy of the cookbooks chef.cookbooks_path = "cookbooks" # Tell chef what recipe to run. In this case, the `vagrant_main` recipe # does all the magic. chef.add_recipe("vagrant_main") chef.json.merge!({ :my_recipe =>{ "foo" =>”bar” }) endend Per Recipe Customization
    24. 24. Provisioning• Chef• Chef-Solo• Puppet• Custom
    25. 25. Provisioning• Chef• Chef-Solo• Puppet• Custom
    26. 26. Chef• Abstracts away configuration details for platform• Provides DSL for managing resources• Idempotent
    27. 27. Chef• Ruby-based infrastructure configuration management tool• Codifies best practices• Installation components called “recipes”• Collection of recipes called “cookbook”• Server-based and standalone
    28. 28. Chef• “Recipes for Chef are like RubyGems for Ruby”
    29. 29. Chef Cookbook
    30. 30. VagrantfileVagrant::Config.run do |config| config.vm.box = "lucid32" config.vm.forward_port ‘web’, 80,4567 # Enable and configure the chef solo provisioner config.vm.provision :chef_solo do |chef| # Were going to use a local copy of the cookbooks chef.cookbooks_path = "cookbooks" # Tell chef what recipe to run. In this case, the `vagrant_main` recipe # does all the magic. chef.add_recipe("vagrant_main") endend Maps VM Port
    31. 31. VagrantfileVagrant::Config.run do |config| config.vm.box = "lucid32" config.vm.forward_port ‘web’, 80,4567 # Enable and configure the chef solo provisioner config.vm.provision :chef_solo do |chef| # Were going to use a local copy of the cookbooks chef.cookbooks_path = "cookbooks" # Tell chef what recipe to run. In this case, the `vagrant_main` recipe # does all the magic. chef.add_recipe("vagrant_main") endend Recipe Metadata Location
    32. 32. VagrantfileVagrant::Config.run do |config| config.vm.box = "lucid32" config.vm.forward_port ‘web’, 80,4567 # Enable and configure the chef solo provisioner config.vm.provision :chef_solo do |chef| # Were going to use a local copy of the cookbooks chef.cookbooks_path = "cookbooks" # Tell chef what recipe to run. In this case, the `vagrant_main` recipe # does all the magic. chef.add_recipe("vagrant_main") endend Which Recipe To Invoke
    33. 33. Demo
    34. 34. Rails App Example
    35. 35. Other Commands$ vagrant provision Only Runs Provisioning Step
    36. 36. Multi-VM SetupsVagrant::Config.run do |config| config.vm.define :web do |web_config| web_config.vm.box = "web" web_config.vm.forward_port("http", 80, 8080) web_config.vm.network("192.168.1.10") end config.vm.define :db do |db_config| db_config.vm.box = "db" db_config.vm.forward_port("db", 3306, 3306) db_config.vm.network("192.168.1.11") endend
    37. 37. Packaging Own Box• Allows you to share a provisioned box
    38. 38. $ vagrant package --include Vagrantfile$ vagrant box add tst package.box #other person adds Create Box and Add It
    39. 39. Mike Hagedorn• @mwhagedorn• mike@silverchairsolutions.com• https://github.com/mwhagedorn/lsrc• spkr8.com/t/7809 Resources• http://vagrantup.com• http://vagrantbox.es• http://wiki.opscode.com/display/chef/Home• http://community.opscode.com

    ×