2. The Old Way
● Provision Server
● Install packages
– Apt-get
– Install from source
– Perl/Bash scripts scripts
● Not very scalable
● Can't version control your servers
● Hard to fully automate
3. The New Way
● Provision Server
● Run Chef to configure
● Highly scalable
● Very modular
● Recipes are Ruby DSL, checked into Git
● Can be fully automated with minimal effort
4. Getting Started - the Parts
● VirtualBox
– Open Source virtualization software
● Chef (Solo)
– Framework for configuring servers
– Write your recipes in Ruby
● Vagrant
– virtualization wrapper for VirtualBox, VMWare, AWS, etc.
– Allows you to bootstrap with Chef (or Puppet)
5. Getting Started
● Download and Install:
– VirtualBox: https://www.virtualbox.org/wiki/Downloads
– Vagrant: http://downloads.vagrantup.com/
● Checkout Gazelle cookbooks:
– git clone --recursive
https://github.com/secondrotation/secondrotation_chef.git
– (Make sure you use recursive so you get the submodules)
6. Create the first VM
● Create an Ubuntu 12.04 server
● Install Apache2
● Install MySql server 5.5
8. Key Vagrant Commands
● vangrant init – generate Vagrant configuration file
● vagrant up – start VM
● vagrant halt – stop VM
● vagrant reload – restart VM (stop, start)
● vagrant ssh – log into VM
● vagrant –help
9. What does Chef do?
● Allows you to describe the state of a server
● Only acts if the system reflects a different state
● Provides a generic abstraction layer with access to
key attributes (os, hardware, etc.)
● Runs actions in the order you specified (unlike
Puppet)
● Power of Ruby – arrays, looping, logic, Erb
templates, blocks, etc. - It's familiar
11. Resources
● A piece of the system and it's desired state
● Ex:
directory "/tmp/folder" do
owner "root"
group "root"
mode 0755
action :create
end
remote_file "#{Chef::Config[:file_cache_path]}/large-file.tar.gz" do
source "http://www.example.org/large-file.tar.gz"
end
package "git" do
action :install
end
12. More Resources
● And when all else fails:
● Full list online http://docs.opscode.com/resource.html
bash "install_something" do
user "root"
cwd "/tmp"
code <<-EOH
wget http://www.example.com/tarball.tar.gz
tar -zxf tarball.tar.gz
cd tarball
./configure
make
make install
EOH
end
13. Anatomy of a Cookbook
● attributes – default values
● recipes – actual steps to perform
● files – static files, usually configuration
● templates – dynamic files, unusually Erb templates
used for configuration
● definitions – custom resources specific to that
cookbook
● tests – Cucumber & MiniTest, TestKitchen
14. Getting Cookbooks
● Opscode: http://community.opscode.com/cookbooks
● GitHub:
– Opscode's: https://github.com/opscode-cookbooks (135)
– Other People's cookbooks: check out code before using
– Fork and give back!
15. Recipe Run
● Always runs recipes/default.rb
● If you've specified another recipe, run that one: for
example:
– mysql:server:
● First runs recipes/default.rb
● Then runs recipes/server.rb
● It's easy to write spaghetti code
– Refactor, refactor, refactor
17. Final Thoughts
● Chef is not the end all, but another tool in your toolbox
● Good for system configuration documentation
● VM based approach is slow to run for a variety of reasons
– apt-get runs as a single thread
– Compiling code is generally slow
● Docker is an interesting alternative to traditional VM, but
not ready for production