Slide 1

Slide 1 text

Avoiding surprises with Chef and Vagrant Andy Gale andy-gale.com Wednesday, 29 May 13

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

Well, it worked on my machine! Wednesday, 29 May 13

Slide 4

Slide 4 text

Developing in a Virtual Machine • Consistent OS and PHP versions between production and local development • New starters can get going with development straight away • Existing developers can redistribute development platform in case of hardware failure Reasons why we should: Wednesday, 29 May 13

Slide 5

Slide 5 text

Developing in a Virtual Machine • Because it’s a massive pain in the arse • Scared of the command line • There’s a massive overhead keeping the VM up to date • Can never get the networking between you and your VM working Reasons why we don’t: Wednesday, 29 May 13

Slide 6

Slide 6 text

Vagrant Virtualised development made easy vagrantup.com Wednesday, 29 May 13

Slide 7

Slide 7 text

• Install Oracle’s VirtualBox www.virtualbox.org/wiki/Downloads • Install Vagrant (packages for Windows, Mac, Linux) downloads.vagrantup.com • Then... Vagrant Getting started $ vagrant box add precise32 http://files.vagrantup.com/precise32.box $ vagrant init precise32 $ vagrant up Wednesday, 29 May 13

Slide 8

Slide 8 text

• Simple to configure using the Vagrantfile which can be kept in version control Vagrant Configuration Vagrant::Config.run do |config| # Forward guest port 80 to # host port 4567 config.vm.forward_port 80, 4567 end • Apply with “vagrant reload” Wednesday, 29 May 13

Slide 9

Slide 9 text

• A tool for automating the provisioning and management of your servers • Open source • Lots of examples and code to get you started • Integrates brilliantly with Vagrant www.opscode.com/chef/ Wednesday, 29 May 13

Slide 10

Slide 10 text

• Talk from Jose Diaz-Gonzalez at CakeFest 2011 tv.cakephp.org/video/CakeFoundation/2011/10/04/full-stack_cakephp_deployment_by_jose_gonzalez • Or his comprehensive blog posts josediazgonzalez.com/2011/10/03/full-stack-cakephp-deployment-with-chef-and-capistrano/ Getting started Wednesday, 29 May 13

Slide 11

Slide 11 text

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 12

Slide 12 text

Getting started • “Cookbooks” are collections of templates, files and basic Ruby code that describe how to setup something. • There’s community (i.e. Open Source, Free) cookbooks for probably everything you’ll need community.opscode.com • You just need to define a few extra things Wednesday, 29 May 13

Slide 13

Slide 13 text

Chef and Vagrant sitting in a tree + Let’s use Vagrant to create a virtual machine to test our Chef configuration Wednesday, 29 May 13

Slide 14

Slide 14 text

• Install Oracle’s VirtualBox www.virtualbox.org/wiki/Downloads • Install Vagrant (packages for Windows, Mac, Linux) downloads.vagrantup.com • Assuming you have git Let’s go $ git clone git@github.com:salgo/cakefest-vagrant-chef.git $ cd cakefest-vagrant-chef $ ./git-fetch-submodules.sh $ vagrant up Wednesday, 29 May 13

Slide 15

Slide 15 text

But that’s not it • Vagrant also supports provisioning with Puppet or just a custom script if that’s what your company uses • Use your favourite editor, your files appear in /vagrant automatically • Because you can recreate your development environment with “vagrant up” whenever you like, you can save disk space with “vagrant destroy” Wednesday, 29 May 13

Slide 16

Slide 16 text

But that is it. • Questions? • @andygale on Twitter • andy-gale.com on the Web Wednesday, 29 May 13