Michael RichardsonEmail: [email protected]
2© 2011 Energized Work - www.energizedwork.com
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
Chef Architecture
4© 2011 Energized Work - www.energizedwork.com
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
Chef Server• Merb Web application
• API service
• Data stored with CouchDB
• Distributes cookbooks to Chef Clients
6© 2011 Energized Work - www.energizedwork.com
Chef Server Web UI• Merb Web application
• Talks to Chef Server API service
• Data stored with CouchDB
7© 2011 Energized Work - www.energizedwork.com
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
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
Chef Basics
10© 2011 Energized Work - www.energizedwork.com
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
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
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
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
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
Cookbooks – Recipes • Encapsulates resources (fundamental units in Chef)
• Resource:
16© 2011 Energized Work - www.energizedwork.com
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
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
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
#
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
Chef Examples
21© 2011 Energized Work - www.energizedwork.com
22© 2011 Energized Work - www.energizedwork.com
Thank youEmail: [email protected]
Top Related