SlideShare a Scribd company logo
1 of 20
Download to read offline
INtroduction to
                        Chef
                             Cooking 5 Star Infrastructure




Wednesday, November 21, 12
What is Chef ?

                   • Chef is a infrastructure configuration
                     management platform to create
                     infrastructure as code
                   • Policy enforcement tool
                   • Continuous integration tool
                   • What you make it


Wednesday, November 21, 12
Client Server Architecture




Wednesday, November 21, 12
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 Client


Wednesday, November 21, 12
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 data




Wednesday, November 21, 12
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
                             Chef's language or to implement your own classes directly.




Wednesday, November 21, 12
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)
                             etc




Wednesday, November 21, 12
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
Creating cookbooks
                              knife cookbook create MYCOOKBOOK




Wednesday, November 21, 12
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 everything




Wednesday, November 21, 12
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" )
         end

Wednesday, November 21, 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"
             end



Wednesday, November 21, 12
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
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
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
       • nodes




Wednesday, November 21, 12
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
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 it's 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
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
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 repo


Wednesday, November 21, 12
QUESTIONS ?




Wednesday, November 21, 12

More Related Content

What's hot

Puppet atbazaarvoice
Puppet atbazaarvoicePuppet atbazaarvoice
Puppet atbazaarvoice
Dave Barcelo
 
Advanced Technology for Web Application Design
Advanced Technology for Web Application DesignAdvanced Technology for Web Application Design
Advanced Technology for Web Application Design
Bryce Kerley
 
Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3
Drupalcon Paris
 

What's hot (20)

Puppet getting started by Dirk Götz
Puppet getting started by Dirk GötzPuppet getting started by Dirk Götz
Puppet getting started by Dirk Götz
 
Snakes on a Treadmill
Snakes on a TreadmillSnakes on a Treadmill
Snakes on a Treadmill
 
Ruby talk romania
Ruby talk romaniaRuby talk romania
Ruby talk romania
 
PHP API
PHP APIPHP API
PHP API
 
Fatc
FatcFatc
Fatc
 
jQuery Objects
jQuery ObjectsjQuery Objects
jQuery Objects
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Puppet atbazaarvoice
Puppet atbazaarvoicePuppet atbazaarvoice
Puppet atbazaarvoice
 
July 2012 HUG: Overview of Oozie Qualification Process
July 2012 HUG: Overview of Oozie Qualification ProcessJuly 2012 HUG: Overview of Oozie Qualification Process
July 2012 HUG: Overview of Oozie Qualification Process
 
Fixing Growing Pains With Puppet Data Patterns
Fixing Growing Pains With Puppet Data PatternsFixing Growing Pains With Puppet Data Patterns
Fixing Growing Pains With Puppet Data Patterns
 
Advanced Technology for Web Application Design
Advanced Technology for Web Application DesignAdvanced Technology for Web Application Design
Advanced Technology for Web Application Design
 
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
 
May 2012 HUG: Oozie: Towards a scalable Workflow Management System for Hadoop
May 2012 HUG: Oozie: Towards a scalable Workflow Management System for HadoopMay 2012 HUG: Oozie: Towards a scalable Workflow Management System for Hadoop
May 2012 HUG: Oozie: Towards a scalable Workflow Management System for Hadoop
 
Automation and Ansible
Automation and AnsibleAutomation and Ansible
Automation and Ansible
 
PuppetConf. 2016: Puppet Best Practices: Roles & Profiles – Gary Larizza, Puppet
PuppetConf. 2016: Puppet Best Practices: Roles & Profiles – Gary Larizza, PuppetPuppetConf. 2016: Puppet Best Practices: Roles & Profiles – Gary Larizza, Puppet
PuppetConf. 2016: Puppet Best Practices: Roles & Profiles – Gary Larizza, Puppet
 
ACADGILD:: HADOOP LESSON
ACADGILD:: HADOOP LESSON ACADGILD:: HADOOP LESSON
ACADGILD:: HADOOP LESSON
 
Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3
 
Oak Lucene Indexes
Oak Lucene IndexesOak Lucene Indexes
Oak Lucene Indexes
 
ERGroupware
ERGroupwareERGroupware
ERGroupware
 
02 Hadoop deployment and configuration
02 Hadoop deployment and configuration02 Hadoop deployment and configuration
02 Hadoop deployment and configuration
 

Similar to Cooking 5 Star Infrastructure with Chef

Practical introduction to dev ops with chef
Practical introduction to dev ops with chefPractical introduction to dev ops with chef
Practical introduction to dev ops with chef
LeanDog
 
Chef for Openstack
Chef for OpenstackChef for Openstack
Chef for Openstack
Mohit Sethi
 

Similar to Cooking 5 Star Infrastructure with Chef (20)

Configuration management with Chef
Configuration management with ChefConfiguration management with Chef
Configuration management with Chef
 
Chef advance
Chef advanceChef advance
Chef advance
 
Chef, Devops, and You
Chef, Devops, and YouChef, Devops, and You
Chef, Devops, and You
 
Velocity 2011 Chef OpenStack Workshop
Velocity 2011 Chef OpenStack WorkshopVelocity 2011 Chef OpenStack Workshop
Velocity 2011 Chef OpenStack Workshop
 
AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013
AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013
AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013
 
Cookbook refactoring & abstracting logic to Ruby(gems)
Cookbook refactoring & abstracting logic to Ruby(gems)Cookbook refactoring & abstracting logic to Ruby(gems)
Cookbook refactoring & abstracting logic to Ruby(gems)
 
Chef Fundamentals Training Series Module 2: Workstation Setup
Chef Fundamentals Training Series Module 2: Workstation SetupChef Fundamentals Training Series Module 2: Workstation Setup
Chef Fundamentals Training Series Module 2: Workstation Setup
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails App
 
Practical introduction to dev ops with chef
Practical introduction to dev ops with chefPractical introduction to dev ops with chef
Practical introduction to dev ops with chef
 
Chef for openstack
Chef for openstackChef for openstack
Chef for openstack
 
Kickstarter - Chef Opswork
Kickstarter - Chef OpsworkKickstarter - Chef Opswork
Kickstarter - Chef Opswork
 
What Makes a Good Cookbook?
What Makes a Good Cookbook?What Makes a Good Cookbook?
What Makes a Good Cookbook?
 
Ansible, best practices
Ansible, best practicesAnsible, best practices
Ansible, best practices
 
Chef for Openstack
Chef for OpenstackChef for Openstack
Chef for Openstack
 
Node object and roles - Fundamentals Webinar Series Part 3
Node object and roles - Fundamentals Webinar Series Part 3Node object and roles - Fundamentals Webinar Series Part 3
Node object and roles - Fundamentals Webinar Series Part 3
 
Cook Infrastructure with chef -- Justeat.IN
Cook Infrastructure with chef  -- Justeat.INCook Infrastructure with chef  -- Justeat.IN
Cook Infrastructure with chef -- Justeat.IN
 
Chef training - Day2
Chef training - Day2Chef training - Day2
Chef training - Day2
 
DevOps
DevOpsDevOps
DevOps
 
Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to Chef
 
Achieving Infrastructure Portability with Chef
Achieving Infrastructure Portability with ChefAchieving Infrastructure Portability with Chef
Achieving Infrastructure Portability with Chef
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 

Cooking 5 Star Infrastructure with Chef

  • 1. INtroduction to Chef Cooking 5 Star Infrastructure Wednesday, November 21, 12
  • 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 it Wednesday, November 21, 12
  • 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 Client Wednesday, November 21, 12
  • 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 data Wednesday, November 21, 12
  • 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 Chef's language or to implement your own classes directly. Wednesday, November 21, 12
  • 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) etc Wednesday, November 21, 12
  • 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. Creating cookbooks knife cookbook create MYCOOKBOOK Wednesday, November 21, 12
  • 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 everything Wednesday, November 21, 12
  • 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" ) end Wednesday, November 21, 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" end Wednesday, November 21, 12
  • 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. 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. 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 • nodes Wednesday, November 21, 12
  • 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. 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 it's 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. 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. 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 repo Wednesday, November 21, 12