30

Introduction to chef framework

  • Upload
    morgoth

  • View
    2.541

  • Download
    3

Embed Size (px)

DESCRIPTION

Presentation given at 3 December 2010 at SRUG meeting http://srug.pl

Citation preview

Page 1: Introduction to chef framework

Introduction to "Chef" framework

Silesian Ruby Users GroupWojciech Wn¦trzak

December 3, 2010

Page 2: Introduction to chef framework

What Is Chef?

Open Source (Apache License v. 2.0)

Framework

Ruby

Infrastructure con�guration management tool

Page 3: Introduction to chef framework

Chef Is Young

Released on January 15th, 2009

Page 4: Introduction to chef framework

Why To Use Chef?

Only one administration guy in company?

Forces order in system

Existing solutions for your problems

Best practices

Page 5: Introduction to chef framework

How To Use Chef?

chef-client + chef-server

chef-client + Opscode Platform

chef-solo

Page 6: Introduction to chef framework

Chef Server

Ruby gem (chef-server)

Stores cookbooks

Stores information about nodes

Accessbile by REST API

Page 7: Introduction to chef framework

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�!

Page 8: Introduction to chef framework

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�!

Page 9: Introduction to chef framework

Opscode Platform

Free plan (upto 5 nodes)

Con�guration step by step

Organizations and users managment

Page 10: Introduction to chef framework

Chef Client

Ruby gem (chef)

Runs on machine that we want to con�gure

Communicates with chef server

Authenticates using RSA keys

Page 11: Introduction to chef framework

Server � Clients

Page 12: Introduction to chef framework

Chef Solo

Part of chef gem

Standalone run (without connecting to server)

Uses cookbooks from local tarballs

Page 13: Introduction to chef framework

Simple Work�ow

Write cookbook with recipe

Upload it to chef server

De�ne run list by:

� editing node on chef server� passing JSON �le to chef-client

Run chef-client on desired machine

Page 14: Introduction to chef framework

Cookbooks

�Cookbooks for Chef are like RubyGems for

Ruby�1

1I couldn't �nd author

Page 15: Introduction to chef framework

Cookbook Skeleton

Page 16: Introduction to chef framework

Example Attributes File

set[:postgresql][:version] = "8.4"

set[:postgresql][:dir] =

"/etc/postgresql/#{node[:postgresql][:version]}/main"

Page 17: Introduction to chef framework

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

Page 18: Introduction to chef framework

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

Page 19: Introduction to chef framework

Package Providers

Apt

Yum

MacPorts

Many more

Page 20: Introduction to chef framework

Package Providers

Apt

Yum

MacPorts

Many more

Page 21: Introduction to chef framework

Supported Systems

Debian

Gentoo

FreeBSD

MacOSX

Solaris

Windows

And more

Page 22: Introduction to chef framework

Supported Systems

Debian

Gentoo

FreeBSD

MacOSX

Solaris

Windows

And more

Page 23: Introduction to chef framework

Supported Systems

Debian

Gentoo

FreeBSD

MacOSX

Solaris

Windows

And more

Page 24: Introduction to chef framework

Resources2

package

template

�le

user

execute

script (bash, ruby, perl, python, csh)

http_request

deploy

Many more

2http://wiki.opscode.com/display/chef/Resources

Page 25: Introduction to chef framework

Resources2

package

template

�le

user

execute

script (bash, ruby, perl, python, csh)

http_request

deploy

Many more

2http://wiki.opscode.com/display/chef/Resources

Page 26: Introduction to chef framework

Additional Tools - Ohai

Released as a gem � ohai

Collects system con�guration/information

Returns JSON

Page 27: Introduction to chef framework

Additional Tools - Knife

Part of chef gem

Console tool for chef server managment

Page 28: Introduction to chef framework

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

Page 29: Introduction to chef framework

Useful Links

http://www.opscode.com/chef/

http://help.opscode.com/faqs/start/how-to-get-started

http://cookbooks.opscode.com/

https://github.com/opscode/cookbooks

Page 30: Introduction to chef framework

Thank You

Questions?