Slide 1

Slide 1 text

Introduction to Chef Nathen Harvey @nathenharvey FOSDEM 2013 github.com/nathenharvey/wordpress-quick-start

Slide 2

Slide 2 text

Hello! • Technical Community Manager, Opscode • Co-host of the Food Fight Show Podcast

Slide 3

Slide 3 text

The Opscode Story Opscode is… • A provider of infrastructure automation. • Helping hundreds of companies develop fully automated infrastructure behind the firewall and in the cloud. • Supported by a community of thousands of users. • A member of the DevOps movement. • Committed to driving next-generation infrastructure development.

Slide 4

Slide 4 text

What is Chef? Recipes and Cookbooks that describe Infrastructure as Code. Chef enables people to easily build & manage complex & dynamic applications at massive scale • New model for describing infrastructure that promotes reuse • Programmatically provision and configure • Reconstruct business from code repository, data backup, and bare metal resources Chef is an automation platform for developers & systems engineers to continuously define, build, and manage infrastructure. CHEF USES: “ ”

Slide 5

Slide 5 text

http://www.flickr.com/photos/francoforeshock/5716969942/ Configuration Desperation

Slide 6

Slide 6 text

Our Objective Load Balancer Database Web Server Web Server

Slide 7

Slide 7 text

Building Wordpress • Identify the resources

Slide 8

Slide 8 text

Chef Resources • Have a type. • Have a name. • Have parameters. • Take action to put the resource in the declared state. • Can send notifications to other resources. package "haproxy" do action :install end template "/etc/haproxy/haproxy.cfg" do source "haproxy.cfg.erb" owner "root" group "root" mode 0644 notifies :restart, "service[haproxy]" end service "haproxy" do supports :restart => true action [:enable, :start] end

Slide 9

Slide 9 text

Building Wordpress • Identify the resources • Write recipes • Package recipes in cookbooks

Slide 10

Slide 10 text

Recipes and Cookbooks • Recipes are collections of Resources • Cookbooks contain recipes, templates, files, custom resources, etc • Code re-use and modularity http://www.flickr.com/photos/shutterhacks/4474421855/

Slide 11

Slide 11 text

© Opscode, 2011 – Confidential – DO NOT DISTRIBUTE Chef Provides a Model for Reuse That Works 11 700+ Cookbooks “Yesterday we started open sourcing some of our Opscode Chef work created at bestbuy.com; bit.ly/ yDV9Hl #Splunk #opschef #expectmor”

Slide 12

Slide 12 text

Building Wordpress • Identify the resources • Write recipes • Package recipes in cookbooks • Bundle the recipes into roles

Slide 13

Slide 13 text

Role name: load-balancer run_list: role[base] recipe[fosdem-loadbalancer]

Slide 14

Slide 14 text

Building Wordpress • Identify the resources • Write recipes • Package recipes in cookbooks • Bundle the recipes into roles • Apply the roles to nodes

Slide 15

Slide 15 text

Run Lists Server Server Server Server chef-server API chef-client “role[base]”, “role[load-balancer]” node apt default.rb build- essential default.rb loadbalancer default.rb

Slide 16

Slide 16 text

Building Wordpress • Identify the resources • Write recipes • Package recipes in cookbooks • Bundle the recipes into roles • Apply the roles to nodes • Provision Infrastructure

Slide 17

Slide 17 text

Provision with Knife EC2 $ knife ec2 server create -I ami-3d4ff254 -f m1.medium -r 'role[database-server]' $ knife ec2 server create -I ami-3d4ff254 -f m1.medium -r 'role[application-server]' $ knife ec2 server create -I ami-3d4ff254 -f m1.medium -r 'role[application-server]' $ knife ec2 server create -I ami-3d4ff254 -f m1.medium -r 'role[load-balancer]'

Slide 18

Slide 18 text

Chef

Slide 19

Slide 19 text

Search • Chef includes a searchable database of information about your infrastructure

Slide 20

Slide 20 text

Search • Use Search in recipes • db_node = search(:node,"role:database-server") • pool_members = search("node", "role:#{node['haproxy']['app_server_role']} AND chef_environment:#{node.chef_environment}") || [] • Use Search with knife • $ knife search node role:database-server

Slide 21

Slide 21 text

Ruby, when you need it ruby_block "configure-replica-set" do block do require "rubygems" require "mongo" if node['mongodb']['replicaset'].nil? Chef::Log.warn("recipe[mongodb::replset] applied to node without mongodb.replicaset attribute, skipping") next end # Retry 5 times, as we believe that there should # be a mongod accepting connections on localhost conn = nil 10.times do |try| begin conn = Mongo::Connection.new( "localhost", node['mongodb']['port'], :slave_ok => true, :connect_timeout => 5) rescue delay = 2 ** (try + 1) Chef::Log.info("Failed to connect to mongodb, sleeping #{delay}, try #{try}/10") sleep(delay) end end end

Slide 22

Slide 22 text

But wait, there’s more! • Encrypted Data Bags • Environments • Lightweight Resources and Providers • Exception and Report Handlers

Slide 23

Slide 23 text

Thank You! Nathen Harvey @nathenharvey FOSDEM 2013