You are previewing Learning Puppet.
O'Reilly logo
Learning Puppet

Book Description

Build intelligent software stacks with the Puppet configuration management suite

About This Book

  • Develop high-quality Puppet modules in an isolated development environment

  • Manage complex development environments with industry-leading configuration management tool

  • A comprehensive guide to get you started with Puppet development and deployment in virtual environments

  • Who This Book Is For

    If you are new to configuration management and IT automation processes and are looking for better ways to manage system configuration changes at scale, this book is for you. Basic knowledge of Linux System Administration is a prerequisite.

    What You Will Learn

  • Manage your system with Puppet instantly

  • Develop Puppet in an isolated development environment

  • Make your manifests reusable to avoid re-inventing the wheel

  • Automate monitoring to improve the user experience through increased uptime

  • Enable nodes to communicate with each other via Puppet Master

  • Make environment configuration dynamic using stored configurations and PuppetDB

  • Extend Puppet beyond the built-in functionalities

  • Manage your environment through the Puppet Enterprise console

  • In Detail

    Puppet is a cross-platform, open source configuration management utility, which runs on various Unix, Linux, and Windows Microsoft platforms. It allows you to automate all your IT configurations, giving you control of what you do to each node, and also when and how you do it. You’ll be able to build and manage development, test, and production environments independently without requiring previous system administration experience.

    Learning Puppet is a step-by-step guide on how to get started with Puppet development and use Puppet modules as the building blocks to deploy production-ready application cluster in virtual environment.

    You will begin with the installation of development environment on the VirtualBox hypervisor and Puppet Learning VM that will be used as the platform for testing and development of Puppet modules. Next, you will learn how to manage virtual machines and snapshots effectively and enhance the development experience with advanced VirtualBox features.

    Later the book will focus on Puppet module development in detail. You will be guided through the process of utilizing existing modules that are available in the public module repository, write your own modules and use them to deploy a real-world web application that includes features such as monitoring and load balancing. You will then learn to scale your environment and turn your static configuration into a dynamic one through stored configurations and PuppetDB. Finally, the book will provide you with practical advice on Puppet troubleshooting and managing your environment with the wealth of features provided by the Puppet Enterprise console.

    Style and approach

    A comprehensive introductory guide to help you manage your infrastructure with Puppet. All instructions and explanations are supported with screenshots and code examples to ensure you get an easy start with Puppet.

    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 files e-mailed directly to you.

    Table of Contents

    1. Learning Puppet
      1. Table of Contents
      2. Learning Puppet
      3. Credits
      4. About the Author
      5. About the Reviewers
        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. Puppet Development in Isolation
        1. Puppet Manifests
        2. Downloading Oracle VirtualBox
        3. Downloading the Puppet Learning VM
        4. Importing the Puppet Learning VM into VirtualBox
        5. Virtual machine snapshots
        6. Snapshot of the virtual machine
        7. Puppet on command line
          1. Puppet version
            1. The open source Puppet
            2. The Puppet Enterprise edition
          2. Puppet resources
          3. Managing resources from the command line
            1. Puppet dry run
            2. Use Puppet to examine the current state of resources
            3. Puppet is run as a user root
            4. Puppet DSL and manifests
        8. Managing resources with the puppet apply command
        9. Creating Puppet manifests
          1. Idempotency
          2. Puppet command line versus Puppet manifests
          3. Managing files and directories with a file resource
        10. Puppet configuration
        11. Summary
      9. 2. Managing Packages in Puppet
        1. Restoring a snapshot
        2. Introducing VirtualBox Guest Additions
          1. Shared folders
          2. Host-only networking
          3. Configuring shared folders
          4. Configuring the host-only network interface
          5. Testing shared folders
          6. Using the file resource to configure network interface on the virtual machine
            1. Restart networking
          7. Creating the puppet-agent node
            1. Take a snapshot of the virtual machine
            2. Branch the virtual machine by creating a clone from the snapshot
            3. Purging package resources
        3. Summary
      10. 3. My First Puppet Module
        1. Introducing the Puppet module
          1. The Puppet module structure
            1. The Puppet module name format
            2. Generating a Puppet module
          2. A Puppet class
            1. Resources inside the Puppet class
            2. Rename the module directory
            3. Applying a Puppet class
            4. Installing a module from Puppet Forge
            5. Installing Apache HTTP Server
            6. Testing the Apache HTTP Server
            7. Customizing a web server with facts and templates
          3. Puppet templates
            1. Creating a template file
            2. Creating a file resource for the template file
          4. Facts by the facter
            1. Facter on the command line
            2. Accessing facts from the Puppet template
            3. Accessing facts from Puppet manifests
            4. A simple for loop in the Puppet template
          5. Testing repeatable deployment
            1. Shut down the virtual machine
            2. Revert the machine state to the previous snapshot
            3. Reduce memory allocation for the virtual machine
            4. Create a linked virtual machine clone from the snapshot
            5. Power on both the virtual machines and apply the webapp class
        2. Summary
      11. 4. Monitoring Your Web Server
        1. Monitoring the architecture
        2. Creating a Nagios module for the client and server
          1. A recap on the state of virtual machines and snapshots
          2. Cloning the virtual machine for Nagios module development
          3. Generating the Nagios module
          4. Puppetize the Nagios Server installation
            1. Configuring the Nagios Server web interface
            2. Applying the nagios::server class
            3. Verifying Nagios Server installation
          5. Creating nagios::client class
            1. Testing the nagios::client class
        3. Enable monitoring on the web server
          1. Configuring the web server host and checks on the Nagios Server
            1. Creating a Nagios host
        4. Summary
      12. 5. Load Balancing the Cluster
        1. The parameterized class
          1. Calling a class with parameters
          2. Creating a parameterized class
        2. The defined type
          1. Calling the defined type
          2. Creating the defined type
        3. The load balancing architecture
        4. Building the load balancer node
          1. Cloning a new virtual machine for the load balancer
            1. Reducing the virtual machine memory allocation
            2. Creating a snapshot and starting the virtual machine
            3. Creating a load balancer module
            4. Installing the load balancer using class parameters
            5. Deploying the load balancer
            6. Verifying the load balancer deployment
              1. Testing end-to-end functionality
        5. Adding parameters to the loadbalancer class
        6. Load balancing web server nodes
          1. Enabling load balancing on the loadbalancer class
          2. Applying and testing the load balancer
            1. Launching the second web server node
        7. Summary
      13. 6. Scaling Up the Puppet Environment
        1. Puppet Master
          1. The Puppet Master components
            1. Certificate Authority for authorization
            2. Mcollective for orchestration
            3. PuppetDB for exported resources, PuppetDB queries, and reporting
        2. Connecting Puppet Agent with Puppet Master
          1. Creating the bootstrap module for Puppet Master and Puppet Agent
          2. Configuring static IP address on Puppet Master
          3. Defining resource processing order with the arrow notation
          4. Creating class bootstrap::master
          5. Referencing an out-of-scope variable from Puppet template
          6. Conditional statements
            1. The if statement
          7. Creating site.pp file for node classification
          8. Applying bootstrap class on Puppet Master
          9. A first look at the Puppet Enterprise Console
            1. Bypassing the certificate warning message
          10. Logging on to the Puppet Enterprise Console
            1. 503 Service Temporarily Unavailable?
          11. Creating a node group
          12. Bootstrapping Puppet Agent
          13. Applying the bootstrap::agent class via the bootstrap class
          14. Signing the certificate on the Puppet Enterprise Console
          15. Adding nodes to the node group
          16. Deploying the Web Server node against Puppet Master
          17. Bootstrapping Load Balancer and Nagios Server nodes
        3. Summary
      14. 7. Making the Configuration Dynamic
        1. An introduction to PuppetDB and exported resources
          1. Exported resources
          2. Exporting and importing resources
            1. Exporting resources
            2. Importing resources
          3. Testing exported resources
          4. Purging resources
          5. Purging resources with the nagios::purge class
          6. The PuppetDB query
          7. Installing the dalen-puppetdbquery module
          8. Adding puppetdbquery into the RUBYLIB environment variable
          9. Examples of Puppet query commands on the command line
            1. Querying certname with action nodes
            2. Querying facts with action facts
          10. Using the puppetdbquery functions
            1. The query_nodes function
            2. The query_facts function
            3. Creating a custom type for testing PuppetDB queries
          11. Using the PuppetDB query to configure the load balancer
            1. Testing the PuppetDB query manifests on the load balancer node
        2. Summary
      15. 8. Extending Puppet
        1. Puppet functions
          1. Creating a Puppet module for custom functions
          2. Writing a function
          3. Test-driving the Puppet function
            1. Testing a Puppet function on the Puppet Agent node
            2. Testing a Puppet function against Puppet Master
          4. Distributing SSH keys with a Puppet function
            1. Creating a public and private key pair
            2. Writing a Puppet function to distribute a public key
            3. Calling the custom function from the file resource
            4. Testing the password-less SSH session
        2. Creating custom facts
          1. External facts
            1. Creating facts that return structured data
          2. Writing custom facts in Ruby
            1. Creating a custom fact to extract certname
            2. Distributing certname records across the cluster
        3. Summary
      16. 9. The Puppet Enterprise Console
        1. Role-based Access Control
          1. Creating a user and assigning a role
            1. Creating a user account
            2. Enabling login for a user account
            3. Assigning a role to the account
        2. Creating a node group
          1. Signing the Puppet agent's certificate
          2. Adding a node to the node group
          3. Classifying nodes in the Puppet Enterprise Console
            1. Moving the site.pp file temporarily out of the modulepath
        3. Using Live Management
        4. Accessing reports via the Puppet Enterprise Console
        5. Searching nodes with Inventory Search
        6. Summary
      17. 10. Troubleshooting Puppet
        1. Prerequisites
        2. Troubleshooting node definition issues
          1. Making the node definition file and ENC work concurrently
        3. Diagnosing duplicate declaration errors
          1. Using the defined() function to avoid duplicate declarations
          2. Using the $name variable in custom types
        4. Getting around dependency cycle errors
        5. Troubleshooting missing resources
          1. Diagnosing template errors
          2. Diagnosing missing source file errors
        6. Rectifying certificate errors
          1. Listing certificates on the Puppet Master
          2. Removing Puppet certificate on Puppet Master
          3. Regenerating Certificate Signing Request
          4. Signing a certificate on the command line
        7. Finding help online
        8. Summary
      18. Index