Chef Essentials

Book Description

Discover how to deploy software, manage hosts, and scale your infrastructure with Chef

In Detail

Chef is a configuration management tool that turns IT infrastructure into code. Chef provides tools to manage systems at scale. With this book, you will learn how to use the same tools that companies such as Facebook, Riot Games, and use to manage and scale their infrastructure.

This book takes you on a comprehensive tour of Chef's functionality, ranging from its core features to advanced development. You will be brought up to speed with what's new in Chef and how to set up your own Chef infrastructure for individuals, or small or large teams. Once you have the core components, you will get to grips with bootstrapping hosts to then develop and apply cookbooks. If you want to fully leverage Chef, this book will show you advanced recipes to help you handle new types of data providers and resources. By the end of this book, you will be confident in how to manage your infrastructure, scale using the cloud, and extend the built-in functionality of Chef itself.

What You Will Learn

  • Install the Chef server on your own hosts
  • Model your infrastructure using Chef from a small number of hosts to a larger scale
  • Integrate Chef with cloud services
  • Develop custom recipes to deploy your software using Chef
  • Test recipes across multiple platforms
  • Extend Chef's built-in functionality to support custom resources
  • Manage development environments using chef-solo and Vagrant

Table of Contents

  1. Chef Essentials
    1. Table of Contents
    2. Chef Essentials
    3. Credits
    4. About the Author
    5. About the Reviewers
      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. Errata
        2. Piracy
        3. Questions
    8. 1. Installing Chef
      1. Terminology
      2. Working with Chef
        1. Installing chef-solo
        2. The Ruby gem
        3. Managing gems
        4. Verifying that chef-solo works
      3. Installing a Chef server
        1. Requirements and recent changes
        2. Installation requirements
        3. What you will be installing
        4. Getting the installer
        5. Installation outline
        6. Installing on Ubuntu
          1. Downloading the package
          2. Installing the package
        7. Installing on Red Hat Enterprise Linux
          1. Downloading the package
      4. Configuring a Chef server
        1. Understanding how chef-server-ctl works
        2. What's happening on my server?
        3. Verifying that the services are running
      5. Validating that your service is working
        1. Ensuring that your knife configuration works
      6. Summary
    9. 2. Modeling Your Infrastructure
      1. Getting to know Chef
      2. Modeling your infrastructure
        1. Roles
          1. Defining roles
            1. A web application service role
            2. An image-processing role
            3. An image search role
            4. A PostgreSQL service role
            5. A Solr service role
            6. An OpenSSH service role
        2. Implementing a role
        3. Determining which recipes you need
          1. Installing a cookbook
        4. Applying recipes to roles
        5. Mapping your roles to nodes
        6. Converging a node
        7. Environments
      3. Organizing your configuration data
        1. Example attribute data
        2. Data bags
          1. Knowing when to use data bags
      4. Large-scale infrastructure
      5. Summary
    10. 3. Integrating with the Cloud
      1. Leveraging the cloud
        1. Amazon EC2
          1. Installing the EC2 knife plugin
          2. Setting up EC2 authentication
          3. Provisioning an instance
          4. Bootstrapping the instance
          5. Terminating the instance
          6. Removing the Chef node
        2. Rackspace Cloud
          1. Provisioning an instance
          2. Terminating an instance
          3. Removing the Chef node
      2. Summary
    11. 4. Working with Cookbooks
      1. Attributes
        1. Multiple attribute files
          1. Supporting multiple platforms
          2. Loading external attributes
        2. Using attributes
      2. Metadata
      3. Recipes
      4. Resources
        1. Using resources
        2. Overriding a default behavior
      5. Templates
        1. Why use templates?
          1. A quick ERB primer
            1. Executing Ruby
              1. Variable replacement
        2. The template resource
        3. The template variables
          1. Passing variables to a template
          2. Accessing computed configurations
        4. Searching for templates
      6. Definitions
      7. Recipes
        1. Developing recipes
      8. Writing recipes
        1. Starting out small
        2. Installing a simple service
        3. Getting more advanced
      9. Summary
    12. 5. Testing Your Recipes
      1. Testing recipes
      2. RSpec
      3. RSpec and ChefSpec
        1. Testing basics
        2. Comparing RSpec with other testing libraries
        3. Using ChefSpec
      4. Getting started with ChefSpec
        1. Installing ChefSpec
        2. Locking your dependencies in Ruby
        3. Creating a simple recipe and a matching ChefSpec test
          1. Writing a ChefSpec test
          2. Building your recipe
          3. Executing tests
          4. Understanding failures
        4. Expanding your tests
          1. Multiple examples in a spec test
          2. Testing for multiple platforms
      5. Summary
    13. 6. From Development to Deployment
      1. Describing the setup
      2. Deploying software with Chef
      3. Configuring your local environment
      4. Modeling a simple Python application
      5. Managing the cookbooks
        1. Downloading cookbooks
        2. Looking at the database recipe
        3. Looking at your application deployment cookbook
        4. Preparing the directories
        5. Constructing your Python virtual environment
        6. Checking the source code
        7. Installing any extra dependencies
          1. Managing dependencies in Chef
          2. Managing dependencies elsewhere
        8. Using Python's requirements file
        9. Configuring your application
        10. Keeping your application running
      6. Defining roles
        1. Creating the base server role
        2. Creating the database server role
        3. Creating the web server role
      7. Adding users
      8. Provisioning EC2 instances
        1. Configuring the database host
      9. Configuring the web server
      10. Deploying your software
        1. Manually deploying updates
        2. Automating deployment
      11. Summary
    14. 7. Beyond Basic Recipes and Cookbooks
      1. Managing users
        1. Evolution of a shell user recipe
        2. Storing data in data bags
          1. Creating a data bag for users
          2. Searching for data
        3. Searching inside recipes
        4. Enhancing your user cookbook
        5. Distributing SSH keys
          1. Templating the authorized keys
          2. Adding deployment keys
      2. Writing custom extensions
        1. Developing a custom definition
          1. Organizing your code
          2. Writing a definition for using PIP
          3. Defining a full application template
        2. Building a resource
          1. Defining the resource
          2. Implementing the provider
          3. Modifying resources
          4. Loading an existing resource
          5. Declaring that a resource was updated
      3. Working with data bags
        1. Securing your data bags
          1. Secret keys
          2. Encrypting your data
          3. Decrypting your data
          4. Storing keys on nodes
        2. Searching your data
          1. Searching your data bags with knife
          2. Searching your data bags from a recipe
          3. Querying your data
        3. Managing multiple machines with search queries
      4. Summary
    15. 8. Extras You Need to Know
      1. Vagrant and Chef-solo
        1. Installing Vagrant
        2. Provisioning a new host with Vagrant
        3. Booting your Vagrant image
        4. Combining Vagrant with Chef-solo
          1. Understanding the limitations of Chef-solo
          2. Configuring Chef-solo
          3. Telling Chef-solo what to run
          4. Using roles and data bags with Chef-solo
            1. Injecting custom JSON data
            2. Providing a custom node name
      2. Getting to know the Chef shell
        1. Using the Chef shell
          1. The standalone mode
          2. The solo mode
          3. The client mode
        2. Interacting with the Chef server using the shell
          1. Interacting with data
          2. Searching your data
          3. Editing your data
          4. Transforming data
        3. Executing recipes with Chef shell
          1. Creating a recipe in the shell
          2. Defining node attributes
            1. Setting attributes
            2. Accessing attributes
          3. Using configuration blocks
          4. Interactively executing recipes
        4. Debugging with the Chef shell
          1. Using the breakpoint resource
      3. Integration testing
        1. Using Test Kitchen
          1. Installing Test Kitchen
          2. Testing with Test Kitchen
            1. Building a simple cookbook
            2. Preparing your cookbook for the kitchen
            3. Testing your new cookbook
              1. Provisioning the instance
              2. Converging the newly created instance
              3. Writing a simple test
              4. Combining all the steps
      4. Extending Chef
        1. Writing an Ohai plugin
          1. A note about writing Ohai plugins
        2. Chef with Capistrano
      5. Automation and integration
        1. Automated updates and deployments
      6. Summary
    16. Index

Product Information

  • Title: Chef Essentials
  • Author(s):
  • Release date: September 2014
  • Publisher(s): Packt Publishing
  • ISBN: 9781783983049