Chef Cookbook - Third Edition

Book description

Master over 80 incredibly effective recipes to manage the day-to-day complications in your infrastructure

About This Book

  • Immediately apply Devops techniques and methods, then combine them with powerful Chef tools to manage and automate your infrastructure

  • Address the growing challenges of code management, cloud, and virtualization with Chef quickly

  • Explore and implement the important aspects of Chef Automate using this recipe-based guide

  • Who This Book Is For

    This book is for system engineers and administrators who have a fundamental understanding of information management systems and infrastructure. It is also for DevOps Engineers, IT professionals, and organizations who want to automate and gain greater control of their infrastructures with Chef. No experience with Chef is needed, but may help.

    What You Will Learn

  • Test your cookbooks with Test Kitchen

  • Manage cookbook dependencies with Berkshelf

  • Use reporting to keep track of what happens during the execution of chef-client runs across all of the machines

  • Create custom Ohai and Knife plugins

  • Build a high-availability service using Heartbeat

  • Use a HAProxy to load-balance multiple web servers

  • 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 will help you solve everyday problems with your IT infrastructure with Chef. It will start with recipes that show you how to effectively manage your infrastructure and solve problems with users, applications, and automation. You will then come across a new testing framework, InSpec, to test any node in your infrastructure.

    Further on, you will learn to customize plugins and write cross-platform cookbooks depending on the platform. You will also install packages from a third-party repository and learn how to manage users and applications. Toward the end, you will build high-availability services and explore what Habitat is and how you can implement it.

    Style and approach

    This book follows a recipe-based approach and covers all the important topics you need to know. If you don't want to dig through a whole book before you get started, this book is for you, as it features a set of independent recipes you can try out immediately.

    Table of contents

    1. Chef Cookbook - Third Edition
      1. Table of Contents
      2. Chef Cookbook - Third Edition
      3. Credits
      4. About the Author
      5. About the Reviewer
      6. www.PacktPub.com
        1. eBooks, discount offers, and more
          1. Why Subscribe?
      7. Customer Feedback
      8. 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. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      9. 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. There's more…
          5. See also
        7. Inspecting files on your Chef server with knife
          1. Getting ready
        8. How to do it…
        9. How it works…
        10. There's more…
        11. See also
        12. Defining cookbook dependencies
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        13. Managing cookbook dependencies with Berkshelf
          1. Getting ready
          2. How to do it…
          3. How it works...
          4. There's more...
          5. See also
        14. Using custom knife plugins
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more...
          5. See also
        15. 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
        16. 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
        17. Using roles
          1. Getting ready
          2. How to do it…
          3. How it works...
          4. See also
        18. Using environments
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        19. Freezing cookbooks
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        20. Running the Chef client as a daemon
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
      10. 2. Evaluating and Troubleshooting Cookbooks and Chef Runs
        1. Introduction
        2. Testing your Chef cookbooks with cookstyle and Rubocop
          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 with Foodcritic
          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. Compliance testing with InSpec
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        6. 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
        7. Showing affected nodes before uploading cookbooks
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        8. 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
        9. Using chef-shell
          1. How to do it…
          2. How it works…
          3. There's more…
          4. See also
        10. 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
        11. Debugging Chef client runs
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        12. Inspecting the results of your last Chef run
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        13. Using Reporting to keep track of all your Chef client runs
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        14. Raising and logging exceptions in recipes
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. See also
        15. Diff-ing cookbooks with knife
          1. Getting ready
          2. How to do it…
          3. How it works...
          4. There's more…
          5. See also
        16. 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
      11. 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. Creating your own custom resource
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more...
          5. See also
        9. 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
        10. Creating custom Ohai plugins
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        11. Creating custom knife plugins
          1. Getting ready
          2. How to do it…
          3. How it works...
          4. There's more…
          5. See also
      12. 4. Writing Better Cookbooks
        1. Introduction
        2. Setting 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. 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
      13. 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
      14. 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
          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. Installing nginx from source
          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 Ruby on Rails applications
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more...
          5. See also
        10. Managing Varnish
          1. Getting ready
          2. How to do it…
          3. How it work…
          4. There's more…
          5. See also
        11. Managing your local workstation with Chef Pantry
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
      15. 7. Servers and Cloud Infrastructure
        1. Introduction
        2. 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
        3. 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
        4. 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
        5. Deploying a Nagios monitoring server
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        6. Using HAProxy to load-balance multiple web servers
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        7. Using custom bootstrap scripts
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        8. Managing firewalls with iptables
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        9. 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
        10. Managing Amazon EC2 instances
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. There's more…
          5. See also
        11. Managing applications with Habitat
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      16. Index

    Product information

    • Title: Chef Cookbook - Third Edition
    • Author(s): Matthias Marschall
    • Release date: February 2017
    • Publisher(s): Packt Publishing
    • ISBN: 9781786465351