Introduction to "Chef" framework
Silesian Ruby Users Group
Wojciech Wn¦trzak
December 3, 2010
Slide 2
Slide 2 text
What Is Chef?
Open Source (Apache License v. 2.0)
Framework
Ruby
Infrastructure conguration management tool
Slide 3
Slide 3 text
Chef Is Young
Released on January 15th, 2009
Slide 4
Slide 4 text
Why To Use Chef?
Only one administration guy in company?
Forces order in system
Existing solutions for your problems
Best practices
Slide 5
Slide 5 text
How To Use Chef?
chef-client + chef-server
chef-client + Opscode Platform
chef-solo
Slide 6
Slide 6 text
Chef Server
Ruby gem (chef-server)
Stores cookbooks
Stores information about nodes
Accessbile by REST API
Slide 7
Slide 7 text
Chef Server Elements
CouchDB stores node informations
SOLR data indexing
RabbitMQ helps in indexing
Merb API and web user interface
Slide 8
Slide 8 text
Chef Server Elements
CouchDB stores node informations
SOLR data indexing
RabbitMQ helps in indexing
Merb API and web user interface
That is lot of stu!
Slide 9
Slide 9 text
Opscode Platform
Free plan (upto 5 nodes)
Conguration step by step
Organizations and users managment
Slide 10
Slide 10 text
Chef Client
Ruby gem (chef)
Runs on machine that we want to congure
Communicates with chef server
Authenticates using RSA keys
Slide 11
Slide 11 text
Server Clients
Slide 12
Slide 12 text
Chef Solo
Part of chef gem
Standalone run (without connecting to server)
Uses cookbooks from local tarballs
Slide 13
Slide 13 text
Simple Workow
Write cookbook with recipe
Upload it to chef server
Dene run list by:
editing node on chef server
passing JSON le to chef-client
Run chef-client on desired machine
Slide 14
Slide 14 text
Cookbooks
Cookbooks for Chef are like RubyGems for
Ruby
1
1I couldn't nd author
Slide 15
Slide 15 text
Cookbook Skeleton
Slide 16
Slide 16 text
Example Attributes File
set[:postgresql][:version] = "8.4"
set[:postgresql][:dir] =
"/etc/postgresql/{node[:postgresql][:version]}/main"
Slide 17
Slide 17 text
PostgreSQL Server Recipe
include_recipe "postgresql::client"
package "postgresql-{node[:postgresql][:version]}" do
action :install
end
template "{node[:postgresql][:dir]}/postgresql.conf" do
source "postgresql.conf.erb"
owner "postgres"
group "postgres"
mode "0600"
end
service "postgresql-{node[:postgresql][:version]}" do
action :start
end
Slide 18
Slide 18 text
Recipe Features
include_recipe "postgresql::client"
package "postgresql-{node[:postgresql][:version]}"
service "postgresql" do
service_name "postgresql-{node[:postgresql][:version]}"
supports :restart => true, :status => true
action :nothing
end
template "{node[:postgresql][:dir]}/postgresql.conf" do
source "postgresql.conf.erb"
owner "postgres"
group "postgres"
mode "0600"
notifies :restart, "service[postgresql]"
end
Slide 19
Slide 19 text
Package Providers
Apt
Yum
MacPorts
Slide 20
Slide 20 text
Package Providers
Apt
Yum
MacPorts
Many more
Slide 21
Slide 21 text
Supported Systems
Debian
Gentoo
FreeBSD
MacOSX
Solaris
Slide 22
Slide 22 text
Supported Systems
Debian
Gentoo
FreeBSD
MacOSX
Solaris
Windows
Slide 23
Slide 23 text
Supported Systems
Debian
Gentoo
FreeBSD
MacOSX
Solaris
Windows
And more
Slide 24
Slide 24 text
Resources2
package
template
le
user
execute
script (bash, ruby, perl, python, csh)
http_request
deploy
2http://wiki.opscode.com/display/chef/Resources
Slide 25
Slide 25 text
Resources2
package
template
le
user
execute
script (bash, ruby, perl, python, csh)
http_request
deploy
Many more
2http://wiki.opscode.com/display/chef/Resources
Slide 26
Slide 26 text
Additional Tools - Ohai
Released as a gem ohai
Collects system conguration/information
Returns JSON
Slide 27
Slide 27 text
Additional Tools - Knife
Part of chef gem
Console tool for chef server managment
Slide 28
Slide 28 text
Tips
If using RVM, use rvmsudo for chef-client
Take a look at chef bootstrap3
Remember that Ruby (Chef) uses sh, not bash
3http://wiki.opscode.com/display/chef/Bootstrap+Chef+RubyGems+
Installation