INtroduction to                        Chef                             Cooking 5 Star InfrastructureWednesday, November 2...
What is Chef ?                   • Chef is a infrastructure configuration                     management platform to create...
Client Server ArchitectureWednesday, November 21, 12
Chef Components                   • Ohai: Data collector System info and                     statistics                   ...
Chef Structures               •      Roles: is a grouping of cookbooks and recipes shared between a type of               ...
What is in a Cookbook                                              What goes where                   •         Attribute n...
Master chefs tool of                           choice KNIFE              Knife It is used by administrators to interact wi...
Roles                    A role is a way to define certain patterns and processes that exist across nodes    knife node run...
Creating cookbooks                              knife cookbook create MYCOOKBOOKWednesday, November 21, 12
Recipes in Cookbooks             •      Recipe names are related to cookbook structure. Putting recipe[foo::bar] in a node...
Recipe                                                               Simple Example of a Recipe         yum_package "autof...
Common Resources             service "memcached" do             action :nothing             supports :status => true, :sta...
ERB Templates            <%=            if node[:domain] == "dc1.company.org"               node.set[autofs_server] = 10.1...
Data-bags             These are JSON Objects stored as Key value             pairs or sub objects                    {    ...
Attributes     Are simple key value stores that can be set on different object pragmatically       Attributes may be set o...
Working With                                        Attributes            See the full documentation for implementation Ap...
Working OHAI             Ohai detects data about your operating system. It can be used standalone, but             its pri...
Jenkins and Branching                   • Roll forward methodology a rollback is                     a push forward in ver...
Continues integration                          With Chef                   • Automated Testing and Building Env           ...
QUESTIONS ?Wednesday, November 21, 12
Upcoming SlideShare
Loading in …5
×

Cooking 5 Star Infrastructure with Chef

1,428 views

Published on

Chef Introduction I did for my team.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,428
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
14
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Cooking 5 Star Infrastructure with Chef

  1. 1. INtroduction to Chef Cooking 5 Star InfrastructureWednesday, November 21, 12
  2. 2. What is Chef ? • Chef is a infrastructure configuration management platform to create infrastructure as code • Policy enforcement tool • Continuous integration tool • What you make itWednesday, November 21, 12
  3. 3. Client Server ArchitectureWednesday, November 21, 12
  4. 4. Chef Components • Ohai: Data collector System info and statistics • Chef-Server: Code Repository • Chef-client: Client software • Knife: Command line interface • Shef: Testing CLI / Development ClientWednesday, November 21, 12
  5. 5. Chef Structures • Roles: is a grouping of cookbooks and recipes shared between a type of node • Node: is a machine that has roles and attributes assigned to it • Cookbook: a collection of recipes • Recipe: a collection of resources • Resource: basic unit of work, package, service, template, file, exec, etc • Attributes: node data such as IP address, Hostname, any value you set • Data-bag: data store of globally available JSON dataWednesday, November 21, 12
  6. 6. What is in a Cookbook What goes where • Attribute node specify data • Definitions allow you to create new resources by stringing together existing resources. • Files you want to deploy via a cookbook • Template ERB Template files that pull data from the node • Resource custom define resource for the cookbook • Recipes default.rb and other Recipes • Libraries allow you to include arbitrary Ruby code, either to extend Chefs language or to implement your own classes directly.Wednesday, November 21, 12
  7. 7. Master chefs tool of choice KNIFE Knife It is used by administrators to interact with the Chef Server API and the local Chef repository. It provides the capability to manipulate nodes, cookbooks, roles, data-bags, environments, etc., and can also be used to provision cloud resources and to bootstrap systems. knife sub-command [ARGUMENTS] (options) knife data bag create BAG knife cookbook list (options) etcWednesday, November 21, 12
  8. 8. Roles A role is a way to define certain patterns and processes that exist across nodes knife node run_list add NODE "role[ROLE NAME]" knife node run_list add NODE "role[ROLE NAME 1],role[ROLE NAME 2],role[ROLE NAME 3]" knife role list knife role create foobar {     "name": "foobar",     "default_attributes": {     },     "json_class": "Chef::Role",     "run_list": ["recipe[apache2]", "recipe[apache2::mod_ssl]", "role[monitor]"     ],     "description": "",     "chef_type": "role",     "override_attributes": {     } }Wednesday, November 21, 12
  9. 9. Creating cookbooks knife cookbook create MYCOOKBOOKWednesday, November 21, 12
  10. 10. Recipes in Cookbooks • Recipe names are related to cookbook structure. Putting recipe[foo::bar] in a node’s run list results in cookbooks/foo/recipes/bar.rb being downloaded from chef-server and executed. • There is a special recipe in every cookbook called default.rb. It is executed either by specifying recipe[foo] or recipe[foo::default] explicitly. • Default.rb is a good place to put common stuff when writing cookbooks with multiple recipes, but we’re going to keep it simple and just use default.rb for everythingWednesday, November 21, 12
  11. 11. Recipe Simple Example of a Recipe yum_package "autofs" do action :install end service "autofs" do supports :restart => true, :status => true, :reload => true action [:enable, :start] end template "/etc/auto.master" do source "auto.master.erb" owner "root" mode "0644" notifies :restart, resources(:service => "autofs" ) end template "/etc/auto.home" do source "auto.home.erb" owner "root" mode "0644" variables({ ! :fqdn => node[:fqdn], ! :autofs_server => node[:autofs_server], ! }) #notifies :restart, resources(:service => node[:autofs][:service]) notifies :restart, resources(:service => "autofs" ) endWednesday, November 21, 12
  12. 12. Common Resources service "memcached" do action :nothing supports :status => true, :start => true, :stop => true, :restart => true end package "some_package" do provider Chef::Provider::Package::Rubygems end yum_package "netpbm" do action :install end template "/tmp/config.conf" do source "config.conf.erb" variables( :config_var => node[:configs][:config_var] ) end file "/tmp/something" do mode "644" endWednesday, November 21, 12
  13. 13. ERB Templates <%= if node[:domain] == "dc1.company.org" node.set[autofs_server] = 10.1.4.120 end if node[:domain] == "dc2.company.org" node.set[autofs_server] = 10.100.0.11 end %> * -fstype=nfs,rw,nosuid,nodev,intr,soft <%= node[:autofs_server] %>:/ home_vol_01/&Wednesday, November 21, 12
  14. 14. Data-bags These are JSON Objects stored as Key value pairs or sub objects { "id": "some_data_bag_item", "production" : { # Hash with all your data here }, "testing" : { # Hash with all your data here } }Wednesday, November 21, 12
  15. 15. Attributes Are simple key value stores that can be set on different object pragmatically Attributes may be set on the node from the following objects • cookbooks • environments (Chef 0.10.0 or above only) • roles • nodesWednesday, November 21, 12
  16. 16. Working With Attributes See the full documentation for implementation Api default["apache"]["dir"]          = "/etc/apache2" default["apache"]["listen_ports"] = [ "80","443" ] node.default["apache"]["dir"]          = "/etc/apache2" node.default["apache"]["listen_ports"] = [ "80","443" ] node.set[apache2][proxy_to_unicorn] = node[rails][use_unicorn] normal / set Attribute Precedence The precedence of the attributes is as follows, from low to high: 1. default attributes applied in an attributes file 2. default attributes applied in an environment 3. default attributes applied in a role 4. default attributes applied on a node directly in a recipe 5. normal or set attributes applied in an attributes file 6. normal or set attributes applied on a node directly in a recipe 7. override attributes applied in an attributes file 8. override attributes applied in a role 9. override attributes applied in an environment 10.override attributes applied on a node directly in a recipe 11.automatic attributes generated by Ohai default attributes applied in an attributes file have the lowest priority and automatic attributes generated by Ohai have the highest priority. Write your cookbooks with default attributes, but override these with role-specific or node-specific values as necessary.Wednesday, November 21, 12
  17. 17. Working OHAI Ohai detects data about your operating system. It can be used standalone, but its primary purpose is to provide node data to Chef. • When invoked, it collects detailed, extensible information about the machine its running on, including Chef configuration, hostname, FQDN, networking, memory, CPU, platform, and kernel data. • When used standalone, Ohai will print out a JSON data blob for all the known data about your system. • When used with Chef, that JSON output is reported back via "automatic" node attributes to update the node object on the chef-server. • Ohai plugins provide additional information about your system infrastructure - Custom Ohai Plugin to gather that other information.Wednesday, November 21, 12
  18. 18. Jenkins and Branching • Roll forward methodology a rollback is a push forward in version but pervious production push locked branch. • Multiple branches to be compiled • Post Production ( Previous stable push branch) • Pre Production ( Staging 2 push or current push brach ) • Testing ( Smoke testing push in staging 1 )Wednesday, November 21, 12
  19. 19. Continues integration With Chef • Automated Testing and Building Env • Smoke tests on staging 1 environments • Staging 1 one Colo 10% yum repo • Staging 2 multi Colo 50% yum repo • Production 100% yum repoWednesday, November 21, 12
  20. 20. QUESTIONS ?Wednesday, November 21, 12

×