Slide 1

Slide 1 text

Using Vagrant Andy Gale Wednesday, 29 May 13

Slide 2

Slide 2 text

Who are you? Andy Gale andy-gale.com @andygale Wednesday, 29 May 13

Slide 3

Slide 3 text

va·grant/ˈvāgrənt/ Noun: A person without a settled home or regular work who wanders from place to place and lives by begging. What is Vagrant? Wednesday, 29 May 13

Slide 4

Slide 4 text

A way of managing virtual machines • Run different operating systems • Define virtual machines in code • Save your own ass What is Vagrant? Wednesday, 29 May 13

Slide 5

Slide 5 text

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? Wednesday, 29 May 13

Slide 6

Slide 6 text

Your development and production environment are not the same! • Different OS? • Different version of PHP/Python/Ruby? • Diverged package versions? • Different default configuration files? Why Vagrant? Wednesday, 29 May 13

Slide 7

Slide 7 text

• 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? Wednesday, 29 May 13

Slide 8

Slide 8 text

• 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 Why Vagrant? Wednesday, 29 May 13

Slide 9

Slide 9 text

Vagrant sounds good! Wednesday, 29 May 13

Slide 10

Slide 10 text

• Install Oracle’s VirtualBox www.virtualbox.org/wiki/Downloads • Install Vagrant (packages for Windows, Mac, Linux) downloads.vagrantup.com Getting Started Wednesday, 29 May 13

Slide 11

Slide 11 text

Getting Started $ vagrant box add precise32 http://files.vagrantup.com/precise32.box Create a box Intialise a workspace $ cd workspace $ vagrant init precise32 Wednesday, 29 May 13

Slide 12

Slide 12 text

Configuration • Simple to configure using the Vagrantfile - A Ruby DSL - which can be kept in version control • Easy to forward ports: Vagrant::Config.run do |config| # Forward guest port 80 to # host port 4567 config.vm.forward_port 80, 4567 end Wednesday, 29 May 13

Slide 13

Slide 13 text

Configuration config.vm.share_folder "v-data", "/data", "../data" Define shared folder Static IP config.vm.network '192.168.0.100' Set hostname config.vm.host_name = "steve" Boot with GUI config.vm.boot_mode :gui Wednesday, 29 May 13

Slide 14

Slide 14 text

Vagrant Defaults • /vagrant - shares your workspace • Default username "vagrant" • Default password "vagrant" Wednesday, 29 May 13

Slide 15

Slide 15 text

Multiple VMs Vagrant::Config.run do |config| config.vm.define :web do |web_config| web_config.vm.box = "web" web_config.vm.forward_port "http", 80, 8080 end config.vm.define :db do |db_config| db_config.vm.box = "db" db_config.vm.forward_port "db", 3306, 3306 end end Wednesday, 29 May 13

Slide 16

Slide 16 text

It’s alive! Bring box up! $ vagrant up Connection to box $ vagrant ssh Close down box $ vagrant halt Delete box $ vagrant destroy Wednesday, 29 May 13

Slide 17

Slide 17 text

• Install all the packages you need once • Make it the same as your product environment • Make a base box and distribute amongst developers • What time has this actually saved So what else? Wednesday, 29 May 13

Slide 18

Slide 18 text

Package $ vagrant package --vagrantfile Vagrantfile.pkg Wednesday, 29 May 13

Slide 19

Slide 19 text

• Shell • Chef Solo • Chef Server • Puppet • Puppet Server • Build your own Provisioners You can provision with: Wednesday, 29 May 13

Slide 20

Slide 20 text

Provisioners Vagrant::Config.run do |config| config.vm.provision :shell, :path => "test.sh" end Shell Wednesday, 29 May 13

Slide 21

Slide 21 text

Provisioners Vagrant::Config.run do |config| config.vm.provision :chef_solo do |chef| chef.roles_path = "roles" chef.add_role("vm") end end Chef Solo: Wednesday, 29 May 13

Slide 22

Slide 22 text

Provisioners Vagrant::Config.run do |config| config.vm.provision :chef_server do |chef| chef.chef_server_url = "http://chef.inter.net" chef.add_role("vm") end end Chef Server: Wednesday, 29 May 13

Slide 23

Slide 23 text

Provisioners Vagrant::Config.run do |config| config.vm.provision :puppet do |puppet| puppet.mainfests_path = "puppetmanifests" puppet.mainfest_file = "newbox.pp" end end Puppet: Wednesday, 29 May 13

Slide 24

Slide 24 text

Provisioners Vagrant::Config.run do |config| config.vm.provision :puppet_server do |puppet| puppet.puppet_server = "puppet.inter.net" puppet.puppet_node = "vm.internet.net" end end Puppet Server: Wednesday, 29 May 13

Slide 25

Slide 25 text

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 Wednesday, 29 May 13

Slide 26

Slide 26 text

Chef Very brief overview Cookbooks Collections of recipes, templates and other configuration attributes to get stuff done. Recipes Chunks of Ruby code that describe what stuff we need to do to get that stuff done. Wednesday, 29 May 13

Slide 27

Slide 27 text

Chef My First Recipe package "ntp" do action :install end template "/etc/ntp.conf" do source "ntp.conf.erb" owner "root" group "root" mode 0644 notifies :restart, resources(:service => "ntp") end service "ntp" do action :start end Install package Create config file from template Define service and start NTP Restart service when config file changes Wednesday, 29 May 13

Slide 28

Slide 28 text

• Community cookbooks http://community.opscode.com/ • IRC #chef on freenode • Foodfight show podcast http://foodfightshow.org/index.html • Ask me [email protected] Chef Scary but you’re not alone Wednesday, 29 May 13

Slide 29

Slide 29 text

Example Get started with a CakePHP application environment with Vagrant and Chef • Install Oracle’s VirtualBox • Install Vagrant $ git clone [email protected]:salgo/cakefest-vagrant-chef.git $ cd cakefest-vagrant-chef $ ./git-fetch-submodules.sh $ vagrant up Wednesday, 29 May 13

Slide 30

Slide 30 text

• OpenStack • VMWare? • Linux containers? • Write your own? Vagrant and onwards Will soon support new virtualisers Wednesday, 29 May 13

Slide 31

Slide 31 text

• If you’re running OS X make sure OS updates are compatible with VirtualBox - Oracle are quick to release fixes 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 Vagrant Tips Wednesday, 29 May 13

Slide 32

Slide 32 text

Official Boxes Ubuntu Lucid 32 Bit http://files.vagrantup.com/lucid32.box Ubuntu Lucid 64 Bit http://files.vagrantup.com/lucid64.box Ubuntu Precise 32 Bit http://files.vagrantup.com/precise32.box Ubuntu Precise 64 Bit http://files.vagrantup.com/precise64.box Wednesday, 29 May 13

Slide 33

Slide 33 text

Other Boxes Example boxes here Wednesday, 29 May 13

Slide 34

Slide 34 text

Questions? Wednesday, 29 May 13