You are previewing Puppet 4 Essentials - Second Edition.
O'Reilly logo
Puppet 4 Essentials - Second Edition

Book Description

Acquire skills to manage your IT infrastructure effectively with Puppet

About This Book

  • Breeze through Puppet 4’s key features and performance improvements to bring real advantage to your IT infrastructure

  • Discover Puppet best practices to help you avoid common mistakes and pitfalls

  • Blitz through easy-to-follow examples to get to grips with Puppet and succeed with everyday IT automation

  • Who This Book Is For

    If you're an experienced IT professional and a new Puppet user, this book will provide you with all you need to know to go from installation to advanced automation in no time at all. Get a rapid introduction to the essential topics and then tackle Puppet for advanced automation.

    What You Will Learn

  • Write and employ individual Puppet manifests

  • Understand how Puppet implements system abstraction

  • Deploy the Puppet master and agents

  • Leverage and extend Facter to summarize your systems

  • Create modular and reusable Puppet code

  • Extend your code base with publicly available Puppet modules

  • Use the modern features of Puppet 4

  • Separate logic from data using Hiera

  • In Detail

    Puppet is a configuration management tool that allows you to automate all your IT configurations, giving you control over what you do to each Puppet Agent in a network, and when and how you do it. In this age of digital delivery and ubiquitous Internet presence, it's becoming increasingly important to implement scalable and portable solutions, not only in terms of software, but also the systems that run it. The free Ruby-based tool Puppet has established itself as the most successful solution to manage any IT infrastructure. Ranging from local development environments through complex data center setups to scalable cloud implementations, Puppet allows you to handle them all with a unified approach.

    Puppet 4 Essentials, Second Edition gets you started rapidly and intuitively as you’ll put Puppet’s tools to work right away. It will also highlight the changes associated with performance improvements as well as the new language features in Puppet 4.

    We’ll start with a quick introduction to Puppet to get you managing your IT systems quickly. You will then learn about the Puppet Agent that comes with an all-in-one (AIO) package and can run on multiple systems. Next, we’ll show you the Puppet Server for high-performance communication and passenger packages. As you progress through the book, the innovative structure and approach of Puppet will be explained with powerful use cases. The difficulties that are inherent to a complex and powerful tool will no longer be a problem for you as you discover Puppet's fascinating intricacies.

    By the end of the book, you will not only know how to use Puppet, but also its companion tools Facter and Hiera, and will be able to leverage the flexibility and expressive power implemented by their tool chain.

    Style and approach

    This quick learning guide for Puppet follows a practical approach, starting with some basic commands that you can use from the shell right away. It comprises a series of examples that will get you familiar with the most important aspects of Puppet in a flash.

    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. Puppet 4 Essentials Second Edition
      1. Table of Contents
      2. Puppet 4 Essentials Second Edition
      3. Credits
      4. About the Authors
      5. About the Reviewer
        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. Writing Your First Manifests
        1. Getting started
        2. Introducing resources and properties
        3. Interpreting the output of the puppet apply command
          1. Dry-testing your manifest
        4. Adding control structures in manifests
        5. Using variables
          1. Variable types
        6. Controlling the order of evaluation
          1. Declaring dependencies
          2. Error propagation
          3. Avoiding circular dependencies
        7. Implementing resource interaction
        8. Examining the most notable resource types
          1. The user and group types
          2. The exec resource type
          3. The cron resource type
          4. The mount resource type
        9. Summary
      9. 2. The Master and Its Agents
        1. The Puppet Master
          1. Puppet Master and Puppet Server
          2. Setting up the master machine
          3. Creating the master manifest
          4. Inspecting the configuration settings
        2. Setting up the Puppet Agent
          1. The agent's life cycle
          2. Renewing an agent's certificate
          3. Running the agent from cron
        3. Performance considerations
          1. Tuning puppetserver
        4. Using Phusion Passenger with Nginx
          1. Comparing Passenger with puppetserver
        5. Completing the stack with PuppetDB
        6. Troubleshooting SSL issues
        7. Summary
      10. 3. A Peek under the Hood – Facts, Types, and Providers
        1. Summarizing systems with Facter
          1. Accessing and using fact values
          2. Extending Facter with custom facts
            1. Simplifying things using external facts
          3. Goals of Facter
        2. Understanding the type system
          1. The resource type's life cycle on the agent side
        3. Substantiating the model with providers
          1. Resource types with generic providers
          2. Summarizing types and providers
        4. Putting it all together
        5. Summary
      11. 4. Modularizing Manifests with Classes and Defined Types
        1. Introducing classes and defined types
          1. Defining and declaring classes
          2. Creating and using defined types
          3. Understanding and leveraging the differences
        2. Structured design patterns
          1. Writing comprehensive classes
          2. Writing component classes
          3. Using defined types as resource wrappers
          4. Using defined types as resource multiplexers
          5. Using defined types as macros
          6. Exploiting array values using defined types
            1. Using iterator functions
        3. Including classes from defined types
        4. Establishing relationships among containers
          1. Passing events between classes and defined types
          2. Ordering containers
          3. Limitations
          4. The performance implications of container relationships
          5. Mitigating the limitations
            1. The anchor pattern
            2. The contain function
        5. Making classes more flexible through parameters
          1. The caveats of parameterized classes
          2. Preferring the include keyword
        6. Summary
      12. 5. Extending Your Puppet Infrastructure with Modules
        1. An overview of Puppet's modules
          1. Parts of a module
          2. Module structure
          3. Documentation in modules
        2. Maintaining environments
          1. Configuring environment locations
          2. Obtaining and installing modules
          3. Modules' best practices
          4. Putting everything in modules
          5. Avoiding generalization
          6. Testing your modules
            1. Safe testing with environments
        3. Building a specific module
          1. Naming your module
          2. Making your module available to Puppet
          3. Implementing basic module functionality
          4. Creating utilities for derived manifests
            1. Adding configuration items
            2. Allowing customization
            3. Removing unwanted configuration items
            4. Dealing with complexity
          5. Enhancing the agent through plugins
            1. Replacing a defined type with a native type
              1. Naming your type
              2. Creating the resource type interface
              3. Designing sensible parameter hooks
              4. Using resource names
              5. Adding a provider
              6. Declaring management commands
              7. Implementing the basic functionality
              8. Allowing the provider to prefetch existing resources
              9. Making the type robust during provisioning
          6. Enhancing Puppet's system knowledge through facts
          7. Refining the interface of your module through custom functions
          8. Making your module portable across platforms
        4. Finding helpful Forge modules
          1. Identifying modules' characteristics
        5. Summary
      13. 6. Leveraging the Full Toolset of the Language
        1. Templating dynamic configuration files
          1. Learning the template syntax
          2. Using templates in practice
          3. Avoiding performance bottlenecks from templates
        2. Creating virtual resources
          1. Realizing resources more flexibly using collectors
        3. Exporting resources to other agents
          1. Exporting and importing resources
          2. Configuring the master to store exported resources
          3. Exporting SSH host keys
          4. Managing hosts files locally
          5. Automating custom configuration items
          6. Simplifying the configuration of Nagios
          7. Maintaining your central firewall
          8. Removing obsolete exports
        4. Overriding resource parameters
          1. Saving redundancy using resource defaults
        5. Avoiding antipatterns
        6. Summary
      14. 7. New Features from Puppet 4
        1. Upgrading to Puppet 4
          1. Using Puppet 3.8 and environment directories
          2. The new Puppet 4 Master
          3. Updating the Puppet agent
          4. Testing Puppet DSL code
        2. Using the type system
        3. Learning lambdas and functions
        4. Creating Puppet 4 functions
        5. Leveraging the new template engine
        6. Handling multiline with HEREDOC
        7. Breaking old practices
          1. Converting node inheritance
          2. Dealing with bool algebra on Strings
          3. Using strict variable naming
          4. Learning the new reference syntax
          5. Cleaning hyphens in names
          6. No Ruby DSL anymore
          7. Relative class name resolution
          8. Dealing with different data types
        8. Summary
      15. 8. Separating Data from Code Using Hiera
        1. Understanding the need for separate data storage
          1. Consequences of defining data in the manifest
        2. Structuring configuration data in a hierarchy
          1. Configuring Hiera
          2. Storing Hiera data
          3. Choosing your backends
        3. Retrieving and using Hiera values in manifests
          1. Working with simple values
          2. Binding class parameter values automatically
          3. Handling hashes and arrays
        4. Converting resources to data
          1. Choosing between manifest and Hiera designs
          2. A practical example
        5. Debugging Hiera lookups
        6. Implementing the Roles and Profiles pattern
        7. Summary
      16. Index