chef - managing yours servers with code

22

Upload: mrichardson

Post on 27-Jan-2015

118 views

Category:

Technology


3 download

DESCRIPTION

Chef talk i gave back January 2011

TRANSCRIPT

Page 1: Chef - managing yours servers with Code
Page 2: Chef - managing yours servers with Code

Michael RichardsonEmail: [email protected]

2© 2011 Energized Work - www.energizedwork.com

Page 3: Chef - managing yours servers with Code

AgendaChef Architecture• Chef Server• Chef Client• Web UI• Chef Solo• Knife

Chef Basics• Cookbooks• Nodes• Roles• Attributes

Examples

Useful links

3© 2011 Energized Work - www.energizedwork.com

Page 4: Chef - managing yours servers with Code

Chef Architecture

4© 2011 Energized Work - www.energizedwork.com

Page 5: Chef - managing yours servers with Code

Chef Server – Architecture

5© 2011 Energized Work - www.energizedwork.com

Server components:• Chef Server• Chef Server Web UI• CouchDB• RabbitMQ• Chef Solr Indexer• Chef Solr

Client components:• Chef Client• Chef Solo• Knife• Shef

Page 6: Chef - managing yours servers with Code

Chef Server• Merb Web application

• API service

• Data stored with CouchDB

• Distributes cookbooks to Chef Clients

6© 2011 Energized Work - www.energizedwork.com

Page 7: Chef - managing yours servers with Code

Chef Server Web UI• Merb Web application

• Talks to Chef Server API service

• Data stored with CouchDB

7© 2011 Energized Work - www.energizedwork.com

Page 8: Chef - managing yours servers with Code

Knife• Command line interface to Chef

• Alternative to using the Chef-Server Web UI

• Allows you to create, list, edit and delete objects in Chef-Server

8© 2011 Energized Work - www.energizedwork.com

Page 9: Chef - managing yours servers with Code

Chef Client• Clients do all the work

• Communicates with Chef Server via REST

• Downloads, Compiles and Executes cookbooks

• Can run periodically as a daemon or as a single run

• Ohai (part of chef-client). Provides node information to Chef

9© 2011 Energized Work - www.energizedwork.com

Page 10: Chef - managing yours servers with Code

Chef Basics

10© 2011 Energized Work - www.energizedwork.com

Page 11: Chef - managing yours servers with Code

Nodes• A node is a host that runs chef client

• Primary feature of a node are it’s attributes and it’s run list

• Nodes are made up of two prime components

• Recipes

• Roles

11© 2011 Energized Work - www.energizedwork.com

Page 12: Chef - managing yours servers with Code

Nodes – Run List• Run list is a list of the recipes that a node will run

• Order is important

• Can include roles which may have recipes assigned to them

12© 2011 Energized Work - www.energizedwork.com

Page 13: Chef - managing yours servers with Code

Attributes• Nodes and roles have associated attributes (key-value pairs)

• Node and role attributes are used as inputs for resource attributes

• Attributes maybe set on a node from the following objects

• Cookbooks

• Roles

• Nodes

13© 2011 Energized Work - www.energizedwork.com

Page 14: Chef - managing yours servers with Code

Roles• Compose functionality sets for nodes through recipes and attributes

• 2 workflows for managing roles

• Write Ruby or JSON files

• Use Knife or Web UI

14© 2011 Energized Work - www.energizedwork.com

Page 15: Chef - managing yours servers with Code

Cookbooks• Collection of files used to configure a system

/cookbook/ /attributes/ /definitions/ /files/ /libraries/ /metadata.rb /README.rdoc /recipes/ /templates/

• Each cookbook typically configures a single package of service

• Cookbooks are commonly shared in the Chef community

15© 2011 Energized Work - www.energizedwork.com

Page 16: Chef - managing yours servers with Code

Cookbooks – Recipes • Encapsulates resources (fundamental units in Chef)

• Resource:

16© 2011 Energized Work - www.energizedwork.com

Page 17: Chef - managing yours servers with Code

Cookbooks – Recipes • Basic examples of resources

17© 2011 Energized Work - www.energizedwork.com

package "tar" do version "1.16.1-1" action :installend

remote_file "/tmp/testfile" do source "http://build.ew/warfiles/testfile" mode "0644" checksum "08da002l"end

service ”httpd" do supports :status => true, :restart => true, :reload => true action [ :enable, :start ]end

cookbook_file "/tmp/testfile" do source "testfile" mode "0644"end

directory "/tmp/something" do owner "root" group "root" mode "0755" action :createend

template "/tmp/config.conf" do source "config.conf.erb"end

link "/tmp/passwd" do to "/etc/passwd"end

Page 18: Chef - managing yours servers with Code

Cookbooks – Files and templates• Files allow you to distribute files to your servers as part of cookbooks

• Templates are files that have been marked up to include variables

• To allow cookbooks to operate on multiple platforms, files and templates can be found in a number of locations within a cookbook

18© 2011 Energized Work - www.energizedwork.com

Eg in order of priority.

cookbook/templates/webapp01.ew/sudoers.erb

cookbook/templates/ubuntu-8.04/sudoers.erb

cookbook/templates/ubuntu/sudoers.erb

cookbook/templates/default/sudoers.erb

Page 19: Chef - managing yours servers with Code

Cookbooks – Template example• Simple template resource

• Simple ERB template file – templates/default/foo.erb

• Rendered file on client

19© 2011 Energized Work - www.energizedwork.com

node[:fqdn] = ”webapp01.ew"template "/tmp/foo" do source "foo.erb" variables({ :java_app => ”SomethingCool.war" })end

The node <%= node[:fqdn] %> is running the app <%= @java_app %>

# cat /tmp/foo

The node webapp01.ew is running the app SomethingCool.war

#

Page 20: Chef - managing yours servers with Code

Useful links• http://www.opscode.com/

• http://wiki.opscode.com/display/chef/Home• http://wiki.opscode.com/display/chef/Resources

• http://cookbooks.opscode.com/• https://github.com/37signals/37s_cookbooks• https://github.com/opscode/cookbooks

20© 2011 Energized Work - www.energizedwork.com

Page 21: Chef - managing yours servers with Code

Chef Examples

21© 2011 Energized Work - www.energizedwork.com

Page 22: Chef - managing yours servers with Code

22© 2011 Energized Work - www.energizedwork.com

Thank youEmail: [email protected]