Share
Embed
Introduction to Chef - FOSDEM 2013
Quick introduction to Chef given at FOSDEM 2013. The code for this presentation can be found at https://github.com/nathenharvey/wordpress-quick-start
Nathen Harvey
February 02, 2013
Transcript
23 slides
-
Hello! • Technical Community Manager, Opscode • Co-host of the
Food Fight Show Podcast -
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. -
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: “ ” -
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 -
Building Wordpress • Identify the resources • Write recipes •
Package recipes in cookbooks -
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/ -
© 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” -
Building Wordpress • Identify the resources • Write recipes •
Package recipes in cookbooks • Bundle the recipes into roles -
Building Wordpress • Identify the resources • Write recipes •
Package recipes in cookbooks • Bundle the recipes into roles • Apply the roles to nodes -
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 -
Building Wordpress • Identify the resources • Write recipes •
Package recipes in cookbooks • Bundle the recipes into roles • Apply the roles to nodes • Provision Infrastructure -
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]' -
Search • Chef includes a searchable database of information about
your infrastructure -
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 -
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 -
But wait, there’s more! • Encrypted Data Bags • Environments
• Lightweight Resources and Providers • Exception and Report Handlers