Avoiding surprises with Chef and Vagrant

6,162 views
6,062 views

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,162
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Avoiding surprises with Chef and Vagrant

    1. 1. Avoiding surprises with Chef and Vagrant Andy Gale andy-gale.com
    2. 2. 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?
    3. 3. Well, it worked on my machine!
    4. 4. Developing in a Virtual MachineReasons why we should:• 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
    5. 5. Developing in a Virtual MachineReasons why we don’t:• 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
    6. 6. VagrantVirtualised development made easy vagrantup.com
    7. 7. Vagrant Getting started• Install Oracle’s VirtualBox www.virtualbox.org/wiki/Downloads• Install Vagrant (packages for Windows, Mac, Linux) downloads.vagrantup.com• Then...$ vagrant box add precise32 http://files.vagrantup.com/precise32.box$ vagrant init precise32$ vagrant up
    8. 8. Vagrant Configuration• Simple to configure using the Vagrantfile which can be kept in version control Vagrant::Config.run do |config| # Forward guest port 80 to # host port 4567 config.vm.forward_port 80, 4567 end• Apply with “vagrant reload”
    9. 9. • 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/
    10. 10. Getting started• 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/
    11. 11. My first recipepackage "ntp" do  action :install Install packageend Create config filetemplate "/etc/ntp.conf" do from template  source "ntp.conf.erb" Restart service  owner "root" when config file  group "root" changes  mode 0644  notifies :restart, resources(:service => "ntp")endservice "ntp" do  action :start Define service andend start NTP
    12. 12. 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
    13. 13. Chef and Vagrant sitting in a tree + Let’s use Vagrant to create a virtual machine to test our Chef configuration
    14. 14. Let’s go• Install Oracle’s VirtualBox www.virtualbox.org/wiki/Downloads• Install Vagrant (packages for Windows, Mac, Linux) downloads.vagrantup.com• Assuming you have git$ git clone git@github.com:salgo/cakefest-vagrant-chef.git$ cd cakefest-vagrant-chef$ ./git-fetch-submodules.sh$ vagrant up
    15. 15. 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”
    16. 16. But that is it.• Questions?• @andygale on Twitter• andy-gale.com on the Web

    ×