You are previewing Mastering Chef.
O'Reilly logo
Mastering Chef

Book Description

Build, deploy, and manage your IT infrastructure to deliver a successful automated system with Chef in any environment

In Detail

Chef is a configuration management tool that turns IT infrastructure into code. Chef provides tools to manage systems at scale. This book will take you through the Chef code, tools, and components to manage your environments using the Chef server efficiently. The book starts with an introduction to the Chef ecosystem, taking you through the terminologies used in Chef, the anatomy of a chef-client run, and Chef solo. You will learn how to use Knife and its associated plugins to accomplish daily routine tasks in a more efficient way. You will also learn how to speed this up by using Ruby with Chef, which will allow you to write more efficient infrastructure code. This book then introduces you to cookbooks and how to extend chef-client through the use of Lightweight Resource/Provider. It tells you how to keep all kind of configurations in key-value pair efficiently, by introducing you to data bags and templates. Then you will get a walkthrough of Chef's wonderful APIs and the extended functionalities of Chef. By the end of the book you will be so well-versed with Chef that you'll be able to explore some fun uses of Chef, which will allow for better productivity.

What You Will Learn

  • Get familiar with the Chef ecosystem and its associated components

  • Use Ruby and Chef together to write effective infrastructure code

  • Explore various aspects of the Chef API, such as using search in a recipe and with the help of the Knife plugin

  • Write recipes and custom Lightweight Resource/Provider

  • Discover the usage of data bags and templates to customize servers

  • Extend the functionalities of Chef using custom Ohai and Knife plugins

  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

    1. Mastering Chef
      1. Table of Contents
      2. Mastering Chef
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Introduction to the Chef Ecosystem
        1. Different modes of running Chef
        2. Terminology used in the world of Chef
        3. The anatomy of a Chef run
          1. A Chef run using chef-client
            1. Step 1 – Building a node object
            2. Step 2 – Authenticate
            3. Step 3 – Synchronization of cookbooks
            4. Step 4 – Loading of cookbooks and convergence
            5. Step 5 – Reporting and exception handling
          2. Using chef-solo
        4. Setting up a work environment
        5. Summary
      9. 2. Knife and Its Associated Plugins
        1. Introducing Knife
          1. Managing cookbooks
            1. Creating a new cookbook
            2. Uploading a cookbook to chef-server
            3. Getting the list of all the cookbooks on chef-server
            4. Deleting cookbooks
            5. Downloading a cookbook
            6. Deleting multiple cookbooks
          2. Managing environments
            1. Creating an environment
            2. Deleting an environment
            3. Editing an environment
            4. Listing all environments
            5. Displaying information about an environment
          3. Managing roles
            1. Creating a new role
            2. Deleting a role
            3. Editing a role
            4. Listing all available roles
            5. Displaying information about a role
          4. Managing nodes
            1. Creating a node
            2. Listing all available nodes
            3. Displaying information about a node
            4. Editing a node
            5. Adding stuff to the run_list associated with a node
            6. Deleting stuff from the run_list associated with a node
            7. Deleting a node object
          5. Managing an API client
            1. Creating a new client
            2. Listing all available API clients
            3. Displaying information about a client
            4. Deleting an existing client
            5. Reregistering a client
          6. The search command
          7. Bootstrapping a node
          8. Some useful Knife plugins
            1. The knife-ssh plugin
            2. The knife-ec2 plugin
            3. The knife-azure plugin
            4. The knife-google plugin
            5. The knife-push plugin
        2. Summary
      10. 3. Chef and Ruby
        1. Ruby
        2. IRB
        3. Variables and types
        4. Symbols
        5. Basic operations
          1. Arithmetic operators
          2. Comparison operators
          3. Assignment operators
          4. Bitwise operators
          5. Logical operators
          6. The Ruby ternary operator
          7. Ruby range operators
          8. The Ruby defined? operator
        6. Conditional statements and loops
          1. The if statement
          2. The unless statement
          3. The case/when statement
          4. The while loop
          5. The until loop
          6. The for loop
        7. Methods
          1. Blocks
        8. Arrays
          1. Creating an array
          2. Accessing elements of an array
          3. Adding elements to an array
          4. Removing elements from an array
          5. Iterating over an array
          6. Selecting elements of an array
            1. The nondestructive way
            2. The destructive way
        9. Bang methods
        10. Hashes
          1. Creating hashes
          2. Iterating over a hash
        11. Classes and objects
          1. What's an object and a class?
          2. Modules
        12. Summary
      11. 4. Controlling Access to Resources
        1. The bootstrap process
        2. Authentication
          1. chef-client
          2. Knife
          3. Custom API calls
        3. Authorization
          1. The Open Source Chef server
          2. Enterprise Chef
            1. Object permissions
            2. Groups
        4. Summary
      12. 5. Starting the Journey to the World of Recipes
        1. Resources
          1. Guard attributes
          2. Lazy evaluation of attributes
            1. The package resource
            2. The cookbook_file resource
            3. The directory resource
            4. The file resource
            5. The execute resource
            6. The cron resource
            7. The service resource
            8. The bash resource
            9. The template resource
              1. Helper modules
                1. Inline methods
                2. Inline modules
                3. Library modules
              2. Partial templates
        2. Recipes
          1. Attributes
            1. Types of attributes
            2. Including recipes
            3. The run_list
            4. Recipe DSL methods
              1. The platform method
              2. The platform_family method
              3. The value_for_platform method
              4. The value_for_platform_family method
              5. The attribute method
              6. The resources method
        3. Best practices when writing recipes
        4. Summary
      13. 6. Cookbooks and LWRPs
        1. Cookbooks
          1. Authoring a cookbook
          2. Uploading a cookbook to the Chef server
          3. Deleting a cookbook
          4. Testing a cookbook
          5. Cookbook versioning
            1. Operators available for use with versioning
          6. Freezing versions
            1. Maintaining multiple versions of cookbooks
              1. Maximum version control strategy
              2. Branch tracking strategy
        2. Custom resources
          1. Setup
          2. Resource
          3. Provider
            1. Provider DSL
          4. Logging
        3. Summary
      14. 7. Roles and Environments
        1. Managing roles
          1. Using Knife
            1. Creating a new role
            2. Editing an existing role
            3. Deleting an existing role
            4. Showing details about an existing role
            5. Listing all roles on the Chef server
          2. Using Ruby DSL
          3. Using a JSON file
          4. Using the Chef API
          5. Using the Chef server WebUI
        2. Managing environments
          1. Using Knife
            1. Creating a new environment
            2. Editing an environment configuration
            3. Deleting an environment
            4. Displaying all the environments configured on the Chef server
            5. Showing details associated with an environment
            6. Comparing cookbook versions across environments
            7. Creating or editing an environment using the configuration specified in a file
          2. Using Ruby DSL
        3. Setting up an environment on a node
          1. Using Knife
          2. Editing the client.rb file on the node
        4. Role and environment attributes
          1. Attribute precedence
        5. Environment run lists
        6. Summary
      15. 8. Attributes and Their Uses
        1. Attribute naming
        2. Different types of attributes
        3. Different sources of attributes
          1. The attribute file
          2. Recipes
          3. Roles and environments
          4. Ohai
        4. Attribute precedence
        5. Attribute whitelisting
        6. Summary
      16. 9. Ohai and Its Plugin Ecosystem
        1. Running the Ohai binary
        2. Ohai plugins
        3. Custom plugins
          1. Logging in Ohai plugins
        4. Summary
      17. 10. Data Bags and Templates
        1. Data bags
          1. Management of a data bag
            1. Creating a data bag
            2. Editing a data bag item
            3. Deleting a data bag item or a data bag
            4. Getting a list of all the data bags set up on the Chef server
            5. Getting a list of items and their properties
            6. Using the data bags in recipes
          2. Encrypted data bags
        2. Templates
          1. Template resources and a template in action
            1. Partial templates
        3. Summary
      18. 11. Chef API and Search
        1. Prerequisites for using Chef API
        2. Authentication of requests
        3. Endpoints
          1. /users
            1. GET
            2. POST
          2. /users/NAME
            1. DELETE
            2. GET
            3. POST
            4. PUT
          3. /clients
            1. GET
            2. POST
          4. /clients/NAME
            1. DELETE
            2. GET
            3. PUT
          5. /roles
            1. GET
            2. POST
          6. /roles/NAME
            1. DELETE
            2. GET
            3. PUT
          7. /roles/NAME/environments
            1. GET
          8. /roles/NAME/environments/NAME
            1. GET
          9. /cookbooks
            1. GET
          10. /cookbooks/NAME
            1. GET
          11. /cookbooks/NAME/VERSION
            1. DELETE
            2. GET
            3. PUT
          12. /data
            1. GET
            2. POST
          13. /data/NAME
            1. DELETE
            2. GET
            3. POST
          14. /data/NAME/ITEM
            1. DELETE
            2. GET
            3. PUT
          15. /environments
            1. GET
            2. POST
          16. /environments/NAME
            1. DELETE
            2. GET
            3. PUT
          17. /environments/NAME/cookbooks
            1. GET
          18. /environments/NAME/nodes
            1. GET
          19. /environments/NAME/recipes
            1. GET
          20. /environments/NAME/roles/NAME
        4. Search
          1. /search
            1. GET
          2. /search/INDEX
            1. GET
            2. POST
          3. Patterns
            1. Syntax
            2. Exact matching
            3. Wildcard matching
            4. Range matching
            5. Fuzzy matching
          4. Operators
          5. Using search in recipes
        5. Ridley
        6. Summary
      19. 12. Extending Chef
        1. Custom Knife plugins
          1. The skeleton of a Knife plugin
          2. Namespace
          3. Class name
          4. Banner
          5. Dependencies
          6. Requirements
          7. Options
          8. Arguments
          9. The run method
          10. Search inside a custom Knife plugin
          11. knife.rb settings
          12. User interactions
          13. Exception handling
          14. A simple Knife plugin
          15. Distributing plugins using gems
        2. Custom Chef handlers
        3. Summary
      20. 13. (Ab)Using Chef
        1. The dynamic server list in Capistrano using Chef
          1. Installing Capistrano
        2. Capistrano style deployments using Chef's "deploy" resource
          1. Phases of deployment
          2. Callbacks
          3. Actions
          4. Attributes
        3. Extending Chef to bootstrap distributed systems
          1. Running jobs from your workstation
          2. Running jobs from within recipes
        4. Test-driven development with Chef
          1. Development without TDD
          2. Development with TDD
        5. Types of tests
          1. What to use where
            1. How do we simulate a real-world scenario?
            2. Tools
            3. Using Chef in a dynamic environment such as the cloud
        6. Summary
      21. Index