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.
15. Resolved Issues
• Isolation
• Application Code Silo’ed
• Repeatable
• Server Configuration Is Controlled
• Reliable
• Server Configuration is Proven
16. Other Benefits
• Bring New People Up To Speed FAST!
• Server Configuration is Source Controlled
• Easier What-If scenarios With Your System
17. 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
18. Installation
$ gem install vagrant
$ vagrant box add base http://files.vagrantup.com/lucid32.box
$ vagrant init
$ vagrant up
19. 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)
20. Installation
$ gem install vagrant
$ vagrant box add base http://files.vagrantup.com/lucid32.box
$ vagrant init
$ vagrant up
Create Vagrantfile
21. Installation
$ gem install vagrant
$ vagrant box add base http://files.vagrantup.com/lucid32.box
$ vagrant init
$ vagrant up
Launches Instance
27. Customizing
Provisioners
Vagrant::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|
# We're 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” })
end
end
Per Recipe Customization
30. Chef
• Abstracts away configuration details for
platform
• Provides DSL for managing resources
• Idempotent
31. Chef
• Ruby-based infrastructure configuration
management tool
• Codifies best practices
• Installation components called “recipes”
• Collection of recipes called “cookbook”
• Server-based and standalone
32. Chef
• “Recipes for Chef are like RubyGems for Ruby”
34. Vagrantfile
Vagrant::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|
# We're 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")
end
end
Maps VM Port
35. Vagrantfile
Vagrant::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|
# We're 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")
end
end
Recipe Metadata Location
36. Vagrantfile
Vagrant::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|
# We're 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")
end
end
Which Recipe To Invoke
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