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

Book Description

Learn Chef Provisioning like a boss and finally own your infrastructure

About This Book

  • This is the first Chef book focused on provisioning infrastructure as its sole task. The book offers a clear solution to a specific pain point: learn to make your system work faster.

  • Learning better approaches to load balancing and parallelization with this book will save you time

  • By mastering the techniques in this book, you will know how to run an entire fleet of machines without breaking a sweat

  • This book is more helpful than the documentation (, with a stronger guiding voice and clearer explanations and use cases

  • Who This Book Is For

    This book is for Software Engineers, System Administrators, or DevOps Engineers who need to quickly deliver reliably consistent infrastructure at scale. You are expected to have intermediate experience with Chef and Ruby and will be reading this book to advance your knowledge and take your skillset to the next level.

    What You Will Learn

  • Use best practices to describe your entire infrastructure as code

  • Automate and document every aspect of your network, from the hardware of individual nodes to software, middleware, and all containers and clouds

  • Create a perfect model system

  • Make the best possible use of your resources and avoid redundancy

  • Deliver on the promise of Infrastructure as Code

  • Scale with ease by properly provisioning their infrastructure

  • Use the best Test Driven Development methodologies

  • In Detail

    This book will show you the best practices to describe your entire infrastructure as code.

    With the help of this book you can expand your knowledge of Chef because and implement robust and scalable automation solutions. You can automate and document every aspect of your network, from the hardware to software, middleware, and all your containers. You will become familiar with the Chef’s Chef Provisioning tool. You will be able to make a perfect model system where everything is represented as code beneath your fingertips.

    Make the best possible use of your resources, and deliver infrastructure as code, making it as versionable, testable and repeatable as application software

    Style and approach

    By dedicating a whole book solely to the question of provisioning, this book will teach administrators to use Chef as a birds-eye lens for their entire system. It will moves you away from the specifics of each machine and its automations and instead will teach you them how to approach the entire cluster as something different than the sum of its parts. By focusing on infrastructure as code as its own project, the book offers elegant, time-saving solutions for a perfectly described and automated network.

    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 If you purchased this book elsewhere, you can visit and register to have the code file.

    Table of Contents

    1. Mastering Chef Provisioning
      1. Table of Contents
      2. Mastering Chef Provisioning
      3. Credits
      4. Foreword
      5. About the Author
      6. Acknowledgments
      7. About the Reviewer
        1. eBooks, discount offers, and more
          1. Why subscribe?
      9. 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
      10. 1. Setting Up a Development Environment on Your Workstation
        1. Re-introducing Chef
          1. What version of the Chef tools do I use?
          2. References
        2. Filling in the gaps in your Chef knowledge base
          1. Major pieces of a Chef puzzle
          2. The Chef client
          3. The Ohai Chef tool
          4. Recipes and cookbooks
          5. Chef run lists
          6. Chef roles
          7. Chef resources
          8. More things to consider
          9. Data bags
          10. Environments
          11. The Chef supermarket
          12. Chef Development Kit
          13. Setting up an on-premise (private) Chef Server
          14. References
        3. Exploring the Chef Development Kit
          1. The Chef Knife
          2. Community tools
          3. References
        4. Installing Chef Development Kit
          1. Downloading ChefDK
          2. Installing ChefDK
          3. Verifying ChefDK
          4. References
        5. Setting up a standard Chef repo
          1. Using the Chef tool for Chef repo
          2. The repo starter kit
          3. Files for your .chef folder – a safer way
          4. Growing your own tree
          5. Self-signed certificates
          6. References
        6. What else do you need?
          1. Using your favorite editor
          2. Version control systems
          3. Virtualization hypervisor
          4. Vagrant
          5. References
        7. What is chef-apply?
          1. Why is that useful?
          2. References
        8. Summary
      11. 2. Knife Tooling and Plugins
        1. Knife help
          1. References
        2. Knife subcommands
          1. Knife Bootstrap
          2. Knife Node
          3. Knife Diff
          4. Knife Exec
          5. Knife SSH
          6. Knife Search
          7. References
        3. Knife to editor integration
          1. Using the "wait" option
          2. Does my editor require the wait option?
          3. References
        4. Knife Windows plugin
          1. Installing the Knife Windows plugin
          2. Bootstrapping a Windows node
          3. Searching for Windows node data
          4. References
        5. Knife EC2 plugin
          1. Installing the Knife EC2 plugin
          2. Creating an EC2 instance
          3. Bootstrapping an existing EC2 instance
          4. Deleting EC2 instances
          5. References
        6. Creating new Knife plugins
          1. The basic plugin file format
          2. Example – A simpler EC2 Create Server plugin
          3. References
        7. Summary
      12. 3. Leveraging Roles, Environments, and Policies
        1. Using Chef roles
          1. How to create a role
          2. Using per-environment run-lists in roles
          3. Using nested roles
          4. There is a downside to roles
          5. References
        2. Using Chef environments
          1. The _default environment
          2. Creating environments
          3. Specifying cookbook versions in environments
          4. References
        3. Using Chef organizations
          1. Creating organizations
          2. Access control
          3. References
        4. Learning the attribute precedence hierarchy
          1. Understanding attribute precedence factors
          2. Resulting precedence hierarchy
        5. Exploring policies
          1. What exactly is a policy?
          2. Why would I use a policy?
          3. How do I use a policy?
          4. Another example
          5. How to specify the source options for cookbooks
          6. What are the "Gotchas"?
          7. References
        6. Summary
      13. 4. Custom Resources
        1. Out with the old (LWRPs), in with the new (Custom Resources)
          1. What is the difference between the old way and the new way of defining resources?
          2. What is a Custom Resource?
          3. References
        2. Creating an example use case
          1. What is the goal?
          2. Creating the cookbook
          3. Creating the default recipe
          4. The recipe worked, but what is missing?
          5. References
        3. Creating and using a Custom Resource
          1. What makes up a Custom Resource?
          2. Creating the "website" Custom Resource
          3. Using our Custom Resource
          4. References
        4. Making a Custom Resource more reusable
          1. Making a Custom Resource-only cookbook
          2. Reuse the code from the "mywebapp" example
          3. Using the reusable Custom Resource-only cookbook
          4. Handling idempotence
          5. References
        5. Subclassing a Custom Resource
          1. Convert our resource into a library module
          2. Subclassing the library module Custom Resource
          3. References
        6. Summary
      14. 5. Provisioning in the Traditional Data Center
        1. VMware provisioning
          1. Installing the knife-vsphere plugin
          2. Provisioning VMs using the knife-vsphere plugin
          3. Cleaning up our vSphere and Chef environments
          4. Using Chef with VMware and Vagrant
          5. References
        2. OpenStack provisioning
          1. Setting up a DevStack OpenStack all-in-one environment
          2. Deploying the DevStack Host VM
          3. Downloading and installing DevStack
          4. Downloading the demo project rc file and applying it
          5. Adding the security rules to allow ping and ssh traffic
          6. Installing the knife OpenStack plugin
          7. Setting up the DevStack public key
          8. Allocating some floating IP addresses to the project
          9. Configuring the knife-openstack plugin knife settings
          10. Adding a CentOS instance image to provision
          11. Provisioning a new instance
          12. References
        3. Network automation
          1. Automating juniper devices
          2. Automating Cisco systems
          3. Automating F5 LTMs
          4. References
        4. Summary
      15. 6. Provisioning in the Cloud
        1. Provisioning AWS EC2 instances
          1. Understanding EC2 authentication
          2. Creating key pairs
          3. Creating security groups
          4. Installing Chef Server into an EC2 instance
          5. References
        2. Provisioning Microsoft Azure instances
          1. Installing the knife-azure plugin
          2. Configuring the plugin
          3. Verifying the configuration
          4. Generating public/private key pairs
          5. Provisioning virtual machines
          6. Provisioning a new Chef server into Azure
          7. References
        3. Provisioning in the Google Cloud platform
          1. Installing and configuring the knife-google plugin
          2. Creating and registering your key pairs
          3. Provisioning virtual machines with the GCE
          4. Deploying Chef server into a GCE instance
          5. References
        4. Looking at an honorable mention – Linode
          1. References
        5. Provisioning containers in Docker
          1. Setting up a Docker server to host our containers
          2. Installing and using Docker on our Chef Workstation
          3. Using the knife-docker plugin
          4. References
        6. Summary
      16. 7. Test-Driven Development
        1. Analyzing cookbooks with RuboCop
          1. Using RuboCop
          2. Examining the RuboCop output
          3. Customizing RuboCop
          4. References
        2. Analyzing cookbooks with Foodcritic
          1. Using Foodcritic
          2. Examining the Foodcritic output
          3. Customizing Foodcritic
          4. References
        3. Unit testing with ChefSpec
          1. Using ChefSpec
          2. Expanding our tests
          3. References
        4. Integration testing with Kitchen and ServerSpec
          1. Preparing our tests
          2. Kitchen create
          3. Kitchen converge
          4. Kitchen verify
          5. References
        5. Summary
      17. 8. Using Chef Provisioning
        1. What is Chef provisioning?
          1. It's highly idempotent
          2. A hypothetical example
          3. References
        2. How to use Chef Provisioning
          1. Chef Provisioning resources
          2. A Vagrant example
          3. A cloud example with AWS
          4. A Docker example
          5. References
        3. Summary
      18. Index