Puppet Cookbook - Third Edition

Jump-start your Puppet deployment using engaging and practical recipes

Puppet Cookbook - Third Edition

This ebook is included in a Mapt subscription
Thomas Uphill, John Arundel

1 customer reviews
Jump-start your Puppet deployment using engaging and practical recipes
$0.00
$13.50
$44.99
$29.99p/m after trial
RRP $26.99
RRP $44.99
Subscription
eBook
Print + eBook
Start 30 Day Trial
Subscribe and access every Packt eBook & Video.
 
  • 5,000+ eBooks & Videos
  • 50+ New titles a month
  • 1 Free eBook/Video to keep every month
Start Free Trial
 
Preview in Mapt

Book Details

ISBN 139781784394882
Paperback336 pages

Book Description

Puppet is a configuration management system that automates all your IT configurations, giving you control of what you do to each node, when you do it, and how you do it.

Puppet Cookbook Third Edition takes the reader from a basic knowledge of Puppet to a complete and expert understanding of Puppet’s latest and most advanced features. Updated with the latest advancements and best practices, it gives you a clear view on how to "connect the dots" and expands your knowledge to successfully use and extend Puppet.

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.

 

 

Read an Extract from the book

Generating manifests with the Puppet resource command

If you have a server that is already configured as it needs to be, or nearly so, you can capture that configuration as a Puppet manifest. The Puppet resource command generates Puppet manifests from the existing configuration of a system. For example, you can have puppet resource generate a manifest that creates all the users found on the system. This is very useful to take a snapshot of a working system and get its configuration quickly into Puppet.

How to do it...

Here are some examples of using puppet resource to get data from a running system:

  1. To generate the manifest for a particular user, run the following command:
    [root@cookbook ~]# puppet resource user thomas
    user { 'thomas':
      ensure           => 'present',
      comment          => 'thomas Admin User',
      gid              => '1001',
      groups           => ['bin', 'wheel'],
      home             => '/home/thomas',
      password         => '!!',
      password_max_age => '99999',
      password_min_age => '0',
      shell            => '/bin/bash',
      uid              => '1001',
          }
  2. For a particular service, run the following command:
    [root@cookbook ~]# puppet resource service sshd
    service { 'sshd':
      ensure => 'running',
      enable => 'true',
    }
  3. For a package, run the following command:
    [root@cookbook ~]# puppet resource package kernel
    package { 'kernel':
      ensure => '2.6.32-431.23.3.el6',
    }

There's more...

You can use puppet resource to examine each of the resource types available in Puppet. In the preceding examples, we generated a manifest for a specific instance of the resource type, but you can also use puppet resource to dump all instances of the resource:

[root@cookbook ~]# puppet resource service
service { 'abrt-ccpp':
  ensure => 'running',
  enable => 'true',
}
service { 'abrt-oops':
  ensure => 'running',
  enable => 'true',
}
service { 'abrtd':
  ensure => 'running',
  enable => 'true',
}
service { 'acpid':
  ensure => 'running',
  enable => 'true',
}
service { 'atd':
  ensure => 'running',
  enable => 'true',
}
service { 'auditd':
  ensure => 'running',
  enable => 'true',
}

This will output the state of each service on the system; this is because each service is an enumerable resource. When you try the same command with a resource that is not enumerable, you get an error message:

[root@cookbook ~]# puppet resource file
Error: Could not run: Listing all file instances is not supported.  Please specify a file or directory, e.g. puppet resource file /etc

Asking Puppet to describe each file on the system will not work; that's something best left to an audit tool such as tripwire (a system designed to look for changes on every file on the system, http://www.tripwire.com)

 

Table of Contents

Chapter 1: Puppet Language and Style
Introduction
Adding a resource to a node
Using Facter to describe a node
Installing a package before starting a service
Installing, configuring, and starting a service
Using community Puppet style
Creating a manifest
Checking your manifests with Puppet-lint
Using modules
Using standard naming conventions
Using inline templates
Iterating over multiple items
Writing powerful conditional statements
Using regular expressions in if statements
Using selectors and case statements
Using the in operator
Using regular expression substitutions
Using the future parser
Chapter 2: Puppet Infrastructure
Introduction
Installing Puppet
Managing your manifests with Git
Creating a decentralized Puppet architecture
Writing a papply script
Running Puppet from cron
Bootstrapping Puppet with bash
Creating a centralized Puppet infrastructure
Creating certificates with multiple DNS names
Running Puppet from passenger
Setting up the environment
Configuring PuppetDB
Configuring Hiera
Setting node-specific data with Hiera
Storing secret data with hiera-gpg
Using MessagePack serialization
Automatic syntax checking with Git hooks
Pushing code around with Git
Managing Environments with Git
Chapter 3: Writing Better Manifests
Introduction
Using arrays of resources
Using resource defaults
Using defined types
Using tags
Using run stages
Using roles and profiles
Passing parameters to classes
Passing parameters from Hiera
Writing reusable, cross-platform manifests
Getting information about the environment
Importing dynamic information
Passing arguments to shell commands
Chapter 4: Working with Files and Packages
Introduction
Making quick edits to config files
Editing INI style files with puppetlabs-inifile
Using Augeas to reliably edit config files
Building config files using snippets
Using ERB templates
Using array iteration in templates
Using EPP templates
Using GnuPG to encrypt secrets
Installing packages from a third-party repository
Comparing package versions
Chapter 5: Users and Virtual Resources
Introduction
Using virtual resources
Managing users with virtual resources
Managing users' SSH access
Managing users' customization files
Using exported resources
Chapter 6: Managing Resources and Files
Introduction
Distributing cron jobs efficiently
Scheduling when resources are applied
Using host resources
Using exported host resources
Using multiple file sources
Distributing and merging directory trees
Cleaning up old files
Auditing resources
Temporarily disabling resources
Chapter 7: Managing Applications
Introduction
Using public modules
Managing Apache servers
Creating Apache virtual hosts
Creating nginx virtual hosts
Managing MySQL
Creating databases and users
Chapter 8: Internode Coordination
Introduction
Managing firewalls with iptables
Building high-availability services using Heartbeat
Managing NFS servers and file shares
Using HAProxy to load-balance multiple web servers
Managing Docker with Puppet
Chapter 9: External Tools and the Puppet Ecosystem
Introduction
Creating custom facts
Adding external facts
Setting facts as environment variables
Generating manifests with the Puppet resource command
Generating manifests with other tools
Using an external node classifier
Creating your own resource types
Creating your own providers
Creating custom functions
Testing your puppet manifests with rspec-puppet
Using librarian-puppet
Using r10k
Chapter 10: Monitoring, Reporting, and Troubleshooting
Introduction
Noop – the don't change anything option
Logging command output
Logging debug messages
Generating reports
Producing automatic HTML documentation
Drawing dependency graphs
Understanding Puppet errors
Inspecting configuration settings

What You Will Learn

  • Install and set up Puppet for the first time
  • Discover the latest, most advanced, and experimental features of Puppet
  • Bootstrap your Puppet installation
  • Master techniques to deal with centralized and decentralized Puppet deployments
  • Use exported resources and forge modules
  • Create efficient manifests to streamline your deployments
  • Automate Puppet master deployment using Git hooks, r10k, and PuppetDB
  • Make Puppet reliable, performant, and scalable

Authors

Table of Contents

Chapter 1: Puppet Language and Style
Introduction
Adding a resource to a node
Using Facter to describe a node
Installing a package before starting a service
Installing, configuring, and starting a service
Using community Puppet style
Creating a manifest
Checking your manifests with Puppet-lint
Using modules
Using standard naming conventions
Using inline templates
Iterating over multiple items
Writing powerful conditional statements
Using regular expressions in if statements
Using selectors and case statements
Using the in operator
Using regular expression substitutions
Using the future parser
Chapter 2: Puppet Infrastructure
Introduction
Installing Puppet
Managing your manifests with Git
Creating a decentralized Puppet architecture
Writing a papply script
Running Puppet from cron
Bootstrapping Puppet with bash
Creating a centralized Puppet infrastructure
Creating certificates with multiple DNS names
Running Puppet from passenger
Setting up the environment
Configuring PuppetDB
Configuring Hiera
Setting node-specific data with Hiera
Storing secret data with hiera-gpg
Using MessagePack serialization
Automatic syntax checking with Git hooks
Pushing code around with Git
Managing Environments with Git
Chapter 3: Writing Better Manifests
Introduction
Using arrays of resources
Using resource defaults
Using defined types
Using tags
Using run stages
Using roles and profiles
Passing parameters to classes
Passing parameters from Hiera
Writing reusable, cross-platform manifests
Getting information about the environment
Importing dynamic information
Passing arguments to shell commands
Chapter 4: Working with Files and Packages
Introduction
Making quick edits to config files
Editing INI style files with puppetlabs-inifile
Using Augeas to reliably edit config files
Building config files using snippets
Using ERB templates
Using array iteration in templates
Using EPP templates
Using GnuPG to encrypt secrets
Installing packages from a third-party repository
Comparing package versions
Chapter 5: Users and Virtual Resources
Introduction
Using virtual resources
Managing users with virtual resources
Managing users' SSH access
Managing users' customization files
Using exported resources
Chapter 6: Managing Resources and Files
Introduction
Distributing cron jobs efficiently
Scheduling when resources are applied
Using host resources
Using exported host resources
Using multiple file sources
Distributing and merging directory trees
Cleaning up old files
Auditing resources
Temporarily disabling resources
Chapter 7: Managing Applications
Introduction
Using public modules
Managing Apache servers
Creating Apache virtual hosts
Creating nginx virtual hosts
Managing MySQL
Creating databases and users
Chapter 8: Internode Coordination
Introduction
Managing firewalls with iptables
Building high-availability services using Heartbeat
Managing NFS servers and file shares
Using HAProxy to load-balance multiple web servers
Managing Docker with Puppet
Chapter 9: External Tools and the Puppet Ecosystem
Introduction
Creating custom facts
Adding external facts
Setting facts as environment variables
Generating manifests with the Puppet resource command
Generating manifests with other tools
Using an external node classifier
Creating your own resource types
Creating your own providers
Creating custom functions
Testing your puppet manifests with rspec-puppet
Using librarian-puppet
Using r10k
Chapter 10: Monitoring, Reporting, and Troubleshooting
Introduction
Noop – the don't change anything option
Logging command output
Logging debug messages
Generating reports
Producing automatic HTML documentation
Drawing dependency graphs
Understanding Puppet errors
Inspecting configuration settings

Book Details

ISBN 139781784394882
Paperback336 pages
Read More
From 1 reviews

Read More Reviews