What is Vagrant?va·grant/ˈvāgrənt/Noun:A person without a settled home orregular work who wanders from placeto place and lives by begging.
What is Vagrant?A way of managing virtual machines • Run different operating systems • Deﬁne virtual machines in code • Save your own ass
Why Vagrant? Setting up a development environment• Often considered a right of passage• Takes hours, often requires support• Requires documentation that’s always frequently out of date• Breaking your development environment can kill productivity for a day• Produces unpredictable results
Why Vagrant?Your development and production environment are not the same!• Different OS?• Different version of PHP/Python/Ruby?• Diverged package versions?• Different default conﬁguration ﬁles?
Why Vagrant?• Update a website with a new feature.• The feature relies on a PHP module that is required by your web app• Module already installed on your laptop because another project that is hosted elsewhere needed it• It’s not a the server you deploy to, so the entire website stops working• You have no idea why, the same code worked on your machine• It worked on my machine!
Why Vagrant?• Vagrant lowers development environment setup time• Maximizes dev/prod parity• Makes the “works on my machine” excuse a relic of the past. from vagrantup.com
Getting Started Create a$ vagrant box add precise32http://ﬁles.vagrantup.com/precise32.box Intialise a workspace$ cd workspace$ vagrant init precise32
Conﬁguration• Simple to conﬁgure using the Vagrantﬁle - A Ruby DSL - which can be kept in version control• Easy to forward ports: Vagrant::Conﬁg.run do |conﬁg| # Forward guest port 80 to # host port 4567 conﬁg.vm.forward_port 80, 4567 end
Conﬁguration Deﬁne shared folderconﬁg.vm.share_folder "v-data", "/data", "../data" Static IP conﬁg.vm.network 192.168.0.100 Set hostname conﬁg.vm.host_name = "steve" Boot with GUI conﬁg.vm.boot_mode :gui
ProvisionersYou can provision with:• Shell• Chef Solo• Chef Server• Puppet• Puppet Server• Build your own
Provisioners ShellVagrant::Conﬁg.run do |conﬁg| conﬁg.vm.provision :shell, :path =>"test.sh"end
Provisioners Chef Solo:Vagrant::Conﬁg.run do |conﬁg| conﬁg.vm.provision :chef_solo do |chef| chef.roles_path = "roles" chef.add_role("vm") endend
Provisioners Chef Server:Vagrant::Conﬁg.run do |conﬁg| conﬁg.vm.provision :chef_server do |chef| chef.chef_server_url = "http://chef.inter.net" chef.add_role("vm") endend
Provisioners Puppet:Vagrant::Conﬁg.run do |conﬁg| conﬁg.vm.provision :puppet do |puppet| puppet.mainfests_path ="puppetmanifests" puppet.mainfest_ﬁle = "newbox.pp" endend
Provisioners Puppet Server:Vagrant::Conﬁg.run do |conﬁg| conﬁg.vm.provision :puppet_server do |puppet| puppet.puppet_server ="puppet.inter.net" puppet.puppet_node ="vm.internet.net" endend
Provision with Chef• A tool for automating the provisioning and management of your servers• Open source• Lots of examples and code to get you started
Chef Very brief overview CookbooksCollections of recipes, templates and otherconﬁguration attributes to get stuff done. RecipesChunks of Ruby code that describe what stuff we need to do to get that stuff done.
Chef My First Recipe Install packagepackage "ntp" do action :installend Create conﬁg ﬁle from templatetemplate "/etc/ntp.conf" do source "ntp.conf.erb" owner "root" Restart service group "root" when conﬁg ﬁle mode 0644 changes notiﬁes :restart, resources(:service => "ntp")endservice "ntp" do action :start Deﬁne service andend start NTP
Chef Scary but you’re not alone• Community cookbooks http://community.opscode.com/• IRC #chef on freenode• Foodﬁght show podcast http://foodﬁghtshow.org/index.html• Ask me firstname.lastname@example.org
Example Get started with a CakePHP application environment with Vagrant and Chef • Install Oracle’s VirtualBox • Install Vagrant$ git clone email@example.com:salgo/cakefest-vagrant-chef.git$ cd cakefest-vagrant-chef$ ./git-fetch-submodules.sh$ vagrant up
Vagrant and onwards Will soon support new virtualisers• OpenStack• VMWare?• Linux containers?• Write your own?
Vagrant Tips• If you’re running OS X make sure OS updates are compatible with VirtualBox - Oracle are quick to release ﬁxes but best to check• Keep guest additions up to date with https://github.com/dotless-de/vagrant-vbguest• You can play with Chef in Vagrant so there’s no excuse not to try
Official Boxes Ubuntu Lucid 32 Bit http://ﬁles.vagrantup.com/lucid32.box Ubuntu Lucid 64 Bit http://ﬁles.vagrantup.com/lucid64.box Ubuntu Precise 32 Bithttp://ﬁles.vagrantup.com/precise32.box Ubuntu Precise 64 Bithttp://ﬁles.vagrantup.com/precise64.box