DevOps and Chef

87
DevOps Chef & Friday 16 March 12

description

DevOps as a buzzword has had a lot of attention recently. This presentation is my take on the origins and essence of the matter, as well as an introduction to how Chef, the open source configuration management software, can help to solve one of the problems an Operations team faces as it moves towards the DevOps goals.

Transcript of DevOps and Chef

Page 1: DevOps and Chef

DevOps

Chef&

Friday 16 March 12

Page 2: DevOps and Chef

DevOps

Friday 16 March 12

Page 3: DevOps and Chef

Devs Opsvs

Friday 16 March 12

Page 4: DevOps and Chef

Devs Opsvs

Friday 16 March 12

Page 5: DevOps and Chef

Devs Opsvs

The Wall Of Confusion

Friday 16 March 12

Page 6: DevOps and Chef

Change

Stabilityvs

Friday 16 March 12

Page 7: DevOps and Chef

A Meeting of MindsFollow code into the wild

Accept change:become agile

Friday 16 March 12

Page 8: DevOps and Chef

Buzzword: DevOps

Friday 16 March 12

Page 9: DevOps and Chef

Buzzword

Buzzword: DevOpsBuzzword

Buzzword

BuzzwordBuzzword

Buzzword

BuzzwordBuzzword

Friday 16 March 12

Page 10: DevOps and Chef

Buzzword

Buzzword: DevOpsBuzzword

Buzzword

Buzz Lightyear

Buzzword

BuzzwordBuzzword

Buzzword

BuzzwordBuzzwordBuzzword

Buzzword

BuzzwordBuzzword Buzzword

Friday 16 March 12

Page 11: DevOps and Chef

Buzzword

Buzzword: DevOpsBuzzword

Buzzword

Buzz Lightyear

BuzzwordBuzzword

BuzzwordBuzzword

Buzzword

Buzzword

Buzzword

Buzzword

Buzzword

Buzzword

Buzzword

BuzzwordBuzzword

Buzzword

Buzzword

Buzzword

Buzzword

Buzzword

Buzzword

Buzzword

Buzzword Buzzword

Buzz Aldrin

Friday 16 March 12

Page 12: DevOps and Chef

What is DevOps?

Friday 16 March 12

Page 13: DevOps and Chef

What is DevOps?

What is DevOps NOT?

Friday 16 March 12

Page 14: DevOps and Chef

What is DevOps?

What is DevOps NOT?

They are making a play for our jobs

Friday 16 March 12

Page 15: DevOps and Chef

What is DevOps?

What is DevOps NOT?

They are making a play for our jobs

Devs want root

Friday 16 March 12

Page 16: DevOps and Chef

What is DevOps?

What is DevOps NOT?

DevOps is not a job title, it’s a philosophy

They are making a play for our jobs

Devs want root

Friday 16 March 12

Page 17: DevOps and Chef

What is DevOps?

What is DevOps NOT?

DevOps is not a job title, it’s a philosophy

They are making a play for our jobs

Devs want root

So many words

Friday 16 March 12

Page 18: DevOps and Chef

DevOps, for me

Friday 16 March 12

Page 19: DevOps and Chef

DevOps, for me:

Testing

Friday 16 March 12

Page 20: DevOps and Chef

DevOps, for me:

Testing

Monitoring

Friday 16 March 12

Page 21: DevOps and Chef

DevOps, for me:

Testing

Automation

Monitoring

Friday 16 March 12

Page 22: DevOps and Chef

DevOps, for me:Testing

Automation

Monitoring

Friday 16 March 12

Page 23: DevOps and Chef

DevOps, for me:Testing

Automation

Monitoring

Don’t release broken things

Know when things break

Replace/fix broken things instantly

Friday 16 March 12

Page 24: DevOps and Chef

✔ ?Friday 16 March 12

Page 25: DevOps and Chef

SCCS:Source Code Control System

Friday 16 March 12

Page 26: DevOps and Chef

SCCS:Source Code Control System

1972

40 Years Ago!

Friday 16 March 12

Page 27: DevOps and Chef

Revision Control

✔Friday 16 March 12

Page 28: DevOps and Chef

Revision ControlTest Driven Development

✔Friday 16 March 12

Page 29: DevOps and Chef

Revision ControlTest Driven Development

Feature Branches

✔Friday 16 March 12

Page 30: DevOps and Chef

Revision ControlTest Driven Development

Continuous IntegrationFeature Branches

✔Friday 16 March 12

Page 31: DevOps and Chef

Revision ControlTest Driven Development

Continuous IntegrationFeature Branches

Staging Environments

✔Friday 16 March 12

Page 32: DevOps and Chef

Revision ControlTest Driven Development

Continuous IntegrationFeature Branches

Staging Environments AGILE✔

Friday 16 March 12

Page 33: DevOps and Chef

AGILE

Friday 16 March 12

Page 34: DevOps and Chef

AGILE OPS ?

Friday 16 March 12

Page 35: DevOps and Chef

AGILE OPSContinuous Deployment

Feature Flags Dark Launches

Automated RecoveryIMVU - 50+

Etsy - 25 Flickr - 10+

?

Friday 16 March 12

Page 36: DevOps and Chef

Instant FeedbackRollbacks

Confidence

No fear of change

Friday 16 March 12

Page 37: DevOps and Chef

Code Infrastructure

Friday 16 March 12

Page 38: DevOps and Chef

CodeInfrastructure

Friday 16 March 12

Page 39: DevOps and Chef

CodeInfrastructure As

Friday 16 March 12

Page 40: DevOps and Chef

$  ssh  root@web1Last  login:  Tue  Mar  13#  apt-­‐get  install  apache2...#  vim  /etc/apache2/sites-­‐enabled/default.conf...#  /etc/init.d/apache2  restart...#  scp  web2:/root/.ssh/authorized_keys  ~/.ssh

Friday 16 March 12

Page 41: DevOps and Chef

ChefFriday 16 March 12

Page 42: DevOps and Chef

chef-client on noderetrieves

configurationfrom server

use knife to pushconfig to server

use knife to query andssh to clients

SERVER

CLIENT(workstation)

CLIENT(server/node)

Friday 16 March 12

Page 43: DevOps and Chef

Chef/nodes/web1.json

Friday 16 March 12

Page 44: DevOps and Chef

{ "access" : [ "developers", "designers" ], "name": "web1", "run_list": [ "role[base]", "role[web]", "recipe[splunk]" ]}

Friday 16 March 12

Page 45: DevOps and Chef

{ "access" : [ "developers", "designers" ], "name": "web1", "run_list": [ "role[base]", "role[web]", "recipe[splunk]" ]}

Friday 16 March 12

Page 46: DevOps and Chef

Chef/nodes/web1.jsonChef/roles/web.rb

Friday 16 March 12

Page 47: DevOps and Chef

run_list("recipe[apache]", "role[monitoring]")

Friday 16 March 12

Page 48: DevOps and Chef

run_list("recipe[apache]", "role[monitoring]")

Friday 16 March 12

Page 49: DevOps and Chef

Chef/nodes/web1.jsonChef/roles/web.rbChef/cookbooks/apache/ recipes/default.rb

Friday 16 March 12

Page 50: DevOps and Chef

package "apache2" do action :installend

Friday 16 March 12

Page 51: DevOps and Chef

apache_modules = ['wsgi', 'ssl', 'auth_tkt', 'proxy_http', 'headers', 'rewrite', 'status']

apache_modules.each do |mod| apache_module mod do enable true notifies :restart, "service[apache2]" endend

Friday 16 March 12

Page 52: DevOps and Chef

apache_modules = ['wsgi', 'ssl', 'auth_tkt', 'proxy_http', 'headers', 'rewrite', 'status']

apache_modules.each do |mod| apache_module mod do enable true notifies :restart, "service[apache2]" endend

Friday 16 March 12

Page 53: DevOps and Chef

package "apache2" do case node[:platform] when "centos","redhat","fedora","suse" package_name "httpd" when "debian","ubuntu" package_name "apache2-mpm-prefork" end action :installend

Friday 16 March 12

Page 54: DevOps and Chef

package "apache2" do case node[:platform] when "centos","redhat","fedora","suse" package_name "httpd" when "debian","ubuntu" package_name "apache2-mpm-prefork" end action :installend

Friday 16 March 12

Page 55: DevOps and Chef

Chef/nodes/web1.jsonChef/roles/web.rbChef/cookbooks/apache/ recipes/default.rb attributes/default.rb

Friday 16 March 12

Page 56: DevOps and Chef

default[:apache][:version] = "2.2"

Friday 16 March 12

Page 57: DevOps and Chef

package "apache2" do action :install version "#{node[:apache][:version]}"end

Friday 16 March 12

Page 58: DevOps and Chef

Chef/nodes/web1.jsonChef/roles/web.rbChef/cookbooks/apache/ recipes/default.rb attributes/default.rb templates/default/apache2.conf.erb

Friday 16 March 12

Page 59: DevOps and Chef

template "#{node[:apache][:dir]}/apache2.conf" do source "apache2.conf.erb" owner "root" mode 0644 notifies :restart, resources(:service => "apache2")end

Friday 16 March 12

Page 60: DevOps and Chef

It’s all Ruby

Friday 16 March 12

Page 61: DevOps and Chef

It’s all Rubyhttp://wiki.opscode.com/display/chef/Just+Enough+Ruby+for+Chef

“Just Enough Ruby for Chef”

Friday 16 March 12

Page 62: DevOps and Chef

It’s all RubyLet’s hack

Friday 16 March 12

Page 63: DevOps and Chef

Chef/nodes/web1.jsonChef/roles/web.rbChef/cookbooks/apache/ recipes/default.rb attributes/default.rb templates/default/apache2.conf.erb libraries/default.rb

Friday 16 March 12

Page 64: DevOps and Chef

class Chef  class Recipe    def apache_ports(&block)      @node[:apache][:vhosts].each do |vh|       vh[:ports].each do |p|         block.call(p)         end      end    end  endend

Friday 16 March 12

Page 65: DevOps and Chef

apache_ports do |p| firewall_port p do action :open endend

Friday 16 March 12

Page 66: DevOps and Chef

apache_ports do |p| firewall_port p do action :open endend

Friday 16 March 12

Page 67: DevOps and Chef

define :firewall_port, :action => :open do if not params.has_key?(:port) params[:port] = params[:name] end

  if params[:action] == :open    execute "open #{params[:port]}" do      command "iptables -A INPUT --destination-port #{params[:port]} -j ACCEPT"    end  else    execute "close #{params[:port]}" do      command "iptables -A INPUT --destination-port #{params[:port]} -j DROP"    end  endend

Friday 16 March 12

Page 68: DevOps and Chef

Providerspackage "apache2" do action :installend

node[:platform]

apt-get install

brew install

yum install

Friday 16 March 12

Page 69: DevOps and Chef

"#{File.expand_path( Chef::Config[:file_cache_path] )}/handlers/yola.rb"

Friday 16 March 12

Page 70: DevOps and Chef

"#{File.expand_path( Chef::Config[:file_cache_path] )}/handlers/yola.rb"

class YolaHandler < Chef::Handler def report() run_status.updated_resources.each do |r| campfire_speak(r.to_s) end endend

Friday 16 March 12

Page 71: DevOps and Chef

"#{File.expand_path( Chef::Config[:file_cache_path] )}/handlers/yola.rb"

class YolaHandler < Chef::Handler def report() run_status.updated_resources.each do |r| campfire_speak(r.to_s) end endend

Friday 16 March 12

Page 72: DevOps and Chef

Chef/nodes/web1.jsonChef/roles/web.rbChef/cookbooks/apache/ recipes/default.rb attributes/default.rb templates/default/apache2.conf.erb libraries/default.rbChef/environments/production.rb

Friday 16 March 12

Page 73: DevOps and Chef

Chef/nodes/web1.jsonChef/roles/web.rbChef/cookbooks/apache/ recipes/default.rb attributes/default.rb templates/default/apache2.conf.erb libraries/default.rbChef/environments/production.rbChef/environments/testing.rb

Friday 16 March 12

Page 74: DevOps and Chef

default_attributes({ "aws_region" => "usa-east"})

default_attributes({ "aws_region" => "usa-east", "logging" => { "debug" => true }})

Friday 16 March 12

Page 75: DevOps and Chef

Chef/nodes/web1.jsonChef/roles/web.rbChef/cookbooks/apache/ recipes/default.rb attributes/default.rb templates/default/apache2.conf.erb libraries/default.rbChef/environments/production.rbChef/environments/testing.rbChef/data_bags/employees/jonathan.json

Friday 16 March 12

Page 76: DevOps and Chef

{ "name": "Jonathan Hitchcock", "id": "jonathan", "groups": ["developers", "operations"], "ssh_keys": [ { "key": "AAAB3NzC1yc2EAAAABIwAAAQEA3advEyDE0aEo==" } ]}

Friday 16 March 12

Page 77: DevOps and Chef

Provisioning

Friday 16 March 12

Page 78: DevOps and Chef

Provisioning

$ knife ec2 server create -r 'role[webserver]' -I ami-7000f019 -f m1.small

Friday 16 March 12

Page 79: DevOps and Chef

Provisioning

$ knife ec2 server create -r 'role[webserver]' -I ami-7000f019 -f m1.small

Amazon EC2Rackspace Cloud

Openstack

EucalyptusKickstart

libvirt

XENKVM

Vagrant

Friday 16 March 12

Page 80: DevOps and Chef

Integration

configuration data vs configuration logic

Friday 16 March 12

Page 81: DevOps and Chef

Integrationconfiguration

datavs configuration logic

Friday 16 March 12

Page 82: DevOps and Chef

Integration

vs configuration logic

Ohai Collects infrastructure data

Stored and indexed in NoSQL

Search and use

configuration data

Friday 16 March 12

Page 83: DevOps and Chef

Attributes

default

normal

override

automatic

(A side note on)

Friday 16 March 12

Page 84: DevOps and Chef

Attributes

default

normal

override

automatic

cookbooks, data bags

node definitions

for special cases

ohai

(A side note on)

Friday 16 March 12

Page 85: DevOps and Chef

Integration

search(:node, 'role:webbackend') do |wb| haproxy_backend "#{wb[:apache][:port]}" do action :create endend

Systems auto-discover each other

Configuration is responsive to changes

(Back to)

Friday 16 March 12

Page 86: DevOps and Chef

Integration

search(:node, 'role:webbackend') do |wb| haproxy_backend "#{wb[:apache][:port]}" do action :create endend

Systems auto-discover each other

Configuration is responsive to changes

So you don’t have to be!

Friday 16 March 12

Page 87: DevOps and Chef

Jonathan Hitchcock

@vhata

github.com/vhata

Friday 16 March 12