You are previewing Chef Infrastructure Automation Cookbook - Second Edition.
O'Reilly logo
Chef Infrastructure Automation Cookbook - Second Edition

Book Description

Over 80 recipes to automate your cloud and server infrastructure with Chef and its associated toolset

In Detail

Chef is a configuration management tool that lets you automate your more cumbersome IT infrastructure processes and control a large network of computers (and virtual machines) from one master server.

This book takes you through covering the various artifacts of Chef and explains the techniques of building full-fledged real-world solutions. After describing how to use the basic Chef command-line tools such as knife and Berkshelf, the book will show you how to troubleshoot your work. It will also take you through the core concepts of managing users, applications, and your entire cloud infrastructure. This book will help you learn the techniques of the pros by walking you through a host of step-by-step guides to solve real-world infrastructure automation challenges.

What You Will Learn

  • Set up your local development and testing environment for Chef

  • Debug your cookbooks and Chef runs by using the numerous inspection and logging facilities of Chef

  • Drive your cookbooks from external data or node-specific attributes

  • Manage and scale your cloud infrastructure by automating your configuration management

  • Extend Chef to meet your advanced needs by creating custom plugins for knife and Ohai

  • Test your Chef cookbooks and infrastructure by writing examples

  • 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. Chef Infrastructure Automation Cookbook Second Edition
      1. Table of Contents
      2. Chef Infrastructure Automation Cookbook Second Edition
      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. Sections
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        5. Conventions
        6. Reader feedback
        7. Customer support
          1. Errata
          2. Piracy
          3. Questions
      8. 1. Chef Infrastructure
        1. Introduction
        2. Using version control
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Installing the Chef development kit on your workstation
          1. How to do it...
          2. How it works...
          3. See also
        4. Using the hosted Chef platform
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Managing virtual machines with Vagrant
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Creating and using cookbooks
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        7. Inspecting files on your Chef server with knife
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        8. Defining cookbook dependencies
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        9. Managing cookbook dependencies with Berkshelf
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        10. Downloading and integrating cookbooks as vendor branches into your Git repository
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        11. Using custom knife plugins
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        12. Deleting a node from the Chef server
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        13. Developing recipes with local mode
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Running knife in local mode
            2. Moving to hosted Chef or your own Chef server
          5. See also
        14. Using roles
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        15. Using environments
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        16. Freezing cookbooks
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        17. Running Chef client as a daemon
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        18. Using chef-shell
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
      9. 2. Evaluating and Troubleshooting Cookbooks and Chef Runs
        1. Introduction
        2. Testing your Chef cookbooks
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Flagging problems in your Chef cookbooks
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Test-driven development for cookbooks using ChefSpec
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Integration testing your Chef cookbooks with Test Kitchen
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Showing affected nodes before uploading cookbooks
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        7. Overriding a node's run list to execute a single recipe
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        8. Using why-run mode to find out what a recipe might do
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        9. Debugging Chef client runs
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        10. Inspecting the results of your last Chef run
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        11. Raising and logging exceptions in recipes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        12. Diff-ing cookbooks with knife
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        13. Using community exception and report handlers
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        14. Creating custom handlers
          1. Getting ready...
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      10. 3. Chef Language and Style
        1. Introduction
        2. Using community Chef style
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Using attributes to dynamically configure recipes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Calculating values in the attribute files
          5. See also
        4. Using templates
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Mixing plain Ruby with Chef DSL
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Installing Ruby gems and using them in recipes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        7. Using libraries
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        8. Using definitions
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        9. Creating your own Lightweight Resource Providers (LWRP)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        10. Extending community cookbooks by using application wrapper cookbooks
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        11. Creating custom Ohai plugins
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        12. Creating custom knife plugins
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      11. 4. Writing Better Cookbooks
        1. Introduction
        2. Setting the environment variables
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Passing arguments to shell commands
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Overriding attributes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Using search to find nodes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Using knife to search for nodes
            2. Searching for arbitrary node attributes
            3. Using Boolean operators in search
          5. See also
        6. Using data bags
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        7. Using search to find data bag items
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        8. Using encrypted data bag items
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Using a private key file
          5. See also
        9. Accessing data bag values from external scripts
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        10. Getting information about the environment
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        11. Writing cross-platform cookbooks
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Avoiding case statements to set values based on the platform
            2. Declaring support for specific operating systems in your cookbook's metadata
          5. See also
        12. Finding the complete list of operating systems you can use in cookbooks
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        13. Making recipes idempotent by using conditional execution
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      12. 5. Working with Files and Packages
        1. Introduction
        2. Creating configuration files using templates
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Using pure Ruby in templates for conditionals and iterations
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Installing packages from a third-party repository
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Installing software from source
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Running a command when a file is updated
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Distributing directory trees
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        8. Cleaning up old files
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        9. Distributing different files based on the target platform
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      13. 6. Users and Applications
        1. Introduction
        2. Creating users from data bags
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Securing the Secure Shell Daemon (SSHD)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Enabling passwordless sudo
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Managing NTP
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Managing nginx
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Creating nginx virtual hosts
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        8. Creating MySQL databases and users
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        9. Managing WordPress sites
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        10. Managing Ruby on Rails applications
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        11. Managing Varnish
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        12. Managing your local workstation
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      14. 7. Servers and Cloud Infrastructure
        1. Introduction
        2. Creating your infrastructure using Chef Provisioning
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Creating cookbooks from a running system with Blueprint
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Running the same command on many machines at once
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        5. Setting up SNMP for external monitoring services
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Deploying a Nagios monitoring server
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Building high-availability services using heartbeat
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        8. Using HAProxy to load-balance multiple web servers
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        9. Using custom bootstrap scripts
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        10. Managing firewalls with iptables
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        11. Managing fail2ban to ban malicious IP addresses
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        12. Managing Amazon EC2 instances
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        13. Loading your Chef infrastructure from a file with spiceweasel and knife
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      15. Index