O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Puppet 5 Cookbook - Fourth Edition

Book Description

Write custom plugins for Puppet, including facts, providers, and functions

About This Book
  • Grasp recipes that work with centralized and decentralized deployments
  • Explore language differences and enhancements anticipated in Puppet version 5.x
  • Gain expert understanding of Puppet's latest and most advanced features
Who This Book Is For

Puppet 5 Cookbook is for anyone who builds and administers servers, especially in a web operations context. You'll need some experience of Linux systems administration, including familiarity with the command line, filesystem, and text editing. No prior programming experience is required.

What You Will Learn
  • Discover the latest and most advanced features of Puppet
  • Bootstrap your Puppet installation using powerful tools like Rake
  • Master techniques to deal with centralized and decentralized Puppet deployments
  • Use exported resources and forge modules to set up Puppet modules
  • Create efficient manifests to streamline your deployments
  • Automate Puppet master deployment using Git hooks and PuppetDB
  • Make Puppet reliable, performant, and scalable
In Detail

Puppet is a configuration management system that automates all your IT configurations, giving you control of managing each node.Puppet 5 Cookbook will take you through Puppet's latest and most advanced features, including Docker containers, Hiera, and AWS Cloud Orchestration. Updated with the latest advancements and best practices, this book delves into various aspects of writing good Puppet code, which includes using Puppet community style, checking your manifests with puppet-lint, and learning community best practices with an emphasis on real-world implementation.

You will learn to set up, install, and create your first manifests with Puppet version control, and also understand various sysadmin tasks, including managing config files, using Augeas, and generating files from snippets and templates. As the book progresses, you'll explore virtual resources and use Puppet's resource scheduling and auditing features. In the concluding chapters, you'll walk through managing applications and writing your own resource types, providers, and external node classifiers.

By the end of this book, you will have learned to report, log, and debug your system.

Style and approach

A recipe-based guide filled with quick step-by-step instructions that are immediately applicable

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. Title Page
  2. Copyright and Credits
    1. Puppet 5 Cookbook  Fourth Edition
  3. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Sections
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Get in touch
      1. Reviews
  6. Puppet Language and Style
    1. Introduction
    2. Adding a resource to a node
      1. How to do it...
      2. How it works...
      3. See also...
    3. Using facter to describe a node
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Variables
        2. Scope
    4. Using puppet facts
      1. How to do it...
    5. Installing a package before starting a service
      1. How to do it...
      2. How it works...
        1. Learning metaparameters and ordering
        2. Trifecta
        3. Idempotency
    6. Installing, configuring, and starting a service
      1. How to do it...
      2. How it works...
    7. Using community Puppet style
      1. How to do it...
        1. Indentation
        2. Quoting
        3. false
        4. Variables
        5. Parameters
        6. Symlinks
    8. Installing Puppet
      1. How to do it...
    9. Creating a manifest
      1. How to do it...
      2. There's more...
    10. Checking your manifests with puppet-lint
      1. Getting ready
      2. How to do it...
      3. There's more...
      4. See also
    11. Making modules
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Templates
        2. Facts, functions, types, and providers
        3. Third-party modules
          1. Module organization
      4. See also
    12. Using standard naming conventions
      1. How to do it...
      2. There's more...
    13. Using inline templates
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    14. Iterating over multiple items
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Using hashes
        2. Creating arrays with the split function
    15. Writing powerful conditional statements
      1. How to do it...
      2. How it works...
      3. There's more...
        1. elsif branches
        2. Comparisons
        3. Combining expressions
      4. See also
    16. Using regular expressions in if statements
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Capturing patterns
        2. Regular expression syntax
      4. See also
    17. Using selectors and case statements
      1. How to do it...
      2. How it works...
        1. Selector
        2. Case statement
      3. There's more...
        1. Regular expressions
        2. Defaults
    18. Using the in operator
      1. How to do it...
      2. There's more...
    19. Using regular expression substitutions
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    20. Puppet 5 changes
      1. Using the call function
    21. Puppet 4/5 changes
      1. Appending to and concatenating arrays
      2. Merging hashes
      3. Using the sensitive type
      4. Lambda functions
        1. reduce
        2. filter
        3. map
        4. slice
        5. each
      5. Functions in Puppet language
  7. Puppet Infrastructure
    1. Introduction
    2. Managing your manifests with Git
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Creating a decentralized Puppet architecture
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Writing a papply script
      1. How to do it...
      2. How it works...
    5. Running Puppet from cron
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Bootstrapping Puppet with bash
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Creating a centralized Puppet infrastructure
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Creating certificates with multiple DNS names
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Setting up the environment
      1. Getting ready
      2. How to do it...
      3. There's more...
    10. Configuring PuppetDB
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    11. Configuring Hiera
      1. How to do it...
      2. How it works...
      3. There's more...
    12. Environment-specific Hiera
      1. Getting ready
      2. How to do it...
      3. How it works...
    13. Setting node-specific data with Hiera
      1. Getting ready
      2. How to do it...
      3. How it works...
    14. Writing a custom Hiera5 function
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    15. Storing secret data with hiera-eyaml
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    16. Automatic syntax-checking with Git hooks
      1. How to do it...
      2. How it works...
    17. Pushing code around with Git
      1. Getting ready
      2. How to do it...
      3. How it works...
    18. Managing environments with Git
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  8. Writing Better Manifests
    1. Introduction
    2. Using arrays of resources
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Using resource defaults
      1. How to do it...
      2. How it works...
      3. There's more...
    4. Using defined types
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Using tags
      1. How to do it...
      2. There's more...
    6. Using run stages
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    7. Using roles and profiles
      1. How to do it...
      2. How it works...
      3. There's more...
    8. Using data types in Puppet
      1. How to do it...
      2. There's more...
    9. Passing parameters to classes
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Specifying default values
    10. Passing parameters from Hiera
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    11. Writing reusable, cross-platform manifests
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    12. Getting information about the environment
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    13. Importing dynamic information
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    14. Passing arguments to shell commands
      1. How to do it...
      2. How it works...
  9. Working with Files and Packages
    1. Introduction
    2. Making quick edits to config files
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Editing INI-style files with puppetlabs-inifile
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Using Augeas to reliably edit config files
      1. How to do it...
      2. How it works...
      3. There's more...
    5. Building config files using snippets
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Using ERB templates
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    7. Using array iterations in templates
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    8. Using EPP templates
      1. How to do it...
      2. How it works...
      3. There's more...
    9. Using GnuPG to encrypt secrets
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    10. Comparing package versions
      1. How to do it...
      2. How it works...
  10. Users and Virtual Resources
    1. Introduction
    2. Using virtual resources
      1. How to do it...
      2. How it works...
      3. There's more...
    3. Managing users with virtual resources
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Managing users' SSH access
      1. How to do it...
      2. How it works...
      3. There's more...
    5. Managing users' customization files
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    6. Using exported resources
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  11. Managing Resources and Files
    1. Introduction
    2. Distributing cron jobs efficiently
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Scheduling when resources are to be applied
      1. How to do it...
      2. How it works...
      3. There's more...
    4. Using host resources
      1. How to do it...
      2. How it works...
      3. There's more...
    5. Using exported host resources
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Using multiple file sources
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    7. Distributing and merging directory trees
      1. How to do it...
      2. How it works...
      3. There's more...
    8. Cleaning up old files
      1. How to do it...
      2. How it works...
      3. There's more...
    9. Auditing resources
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    10. Temporarily disabling resources
      1. How to do it...
      2. How it works...
  12. Managing Applications
    1. Introduction
    2. Using public modules
      1. How to do it...
      2. How it works...
      3. There's more...
    3. Managing Apache servers
      1. How to do it...
      2. How it works...
    4. Creating Apache virtual hosts
      1. How to do it...
      2. How it works...
      3. There's more...
    5. Creating NGINX virtual hosts
      1. How to do it...
      2. How it works...
      3. There's more...
    6. Managing MariaDB
      1. How to do it...
      2. How it works...
      3. There's more...
    7. Creating databases and users
      1. How to do it...
      2. How it works...
      3. There's more...
  13. Servers and Cloud Infrastructure
    1. Introduction
    2. Managing firewalls with iptables
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Building high-availability services using Keepalived
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Managing NFS servers and file shares
      1. How to do it...
      2. How it works...
    5. Using HAProxy to load balance multiple web servers
      1. How to do it...
      2. How it works...
      3. There's more...
    6. Managing EC2 instances
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Managing virtual machines with Vagrant
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Managing Docker with Puppet
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  14. External Tools and the Puppet Ecosystem
    1. Introduction
    2. Creating custom facts
      1. How to do it...
      2. How it works...
      3. There's more...
    3. Adding external facts
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Debugging external facts
        2. Using external facts in Puppet
    4. Setting facts as environment variables
      1. How to do it...
    5. Generating manifests with the Puppet resource command
      1. How to do it...
      2. There's more...
    6. Generating manifests with other tools
      1. Getting ready
      2. How to do it...
      3. There's more...
    7. Using PDK
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Using an external node classifier
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    9. Creating your own resource types
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Documentation
        2. Validation
    10. Creating your own providers
      1. How to do it...
      2. How it works...
      3. There's more...
    11. Creating custom functions
      1. How to do it...
      2. How it works...
      3. There's more...
    12. Testing your puppet manifests with rspec-puppet
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  15. Monitoring, Reporting, and Troubleshooting
    1. Introduction
    2. Noop—the don't-change-anything option
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Logging the command output
      1. How to do it...
      2. How it works...
      3. There's more...
    4. Logging debug messages
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Resource ordering
    5. Generating reports
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Other report types
      4. See also
    6. Producing automatic HTML documentation
      1. Getting ready...
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Drawing dependency graphs
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. When Puppet looks for the dependencies
      4. There's more...
      5. See also
    8. Understanding Puppet errors
      1. How to do it...
        1. Could not retrieve file metadata for XXX: getaddrinfo: Name or service not known
        2. Could not evaluate: Could not retrieve information from environment production source(s) XXX
        3. Error: Could not set 'file' on ensure: No such file or directory XXX
        4. Change from absent to file failed: Could not set 'file on ensure: No such file or directory
        5. Undefined method 'closed?' for nil:NilClass
        6. Duplicate definition: X is already defined in [file] at line Y; cannot redefine at [file] line Y
      2. See also
    9. Inspecting configuration settings
      1. How to do it...
      2. How it works...
      3. See also
  16. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think