Puppet Cookbook - Third Edition

More Information
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
About

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)

 
Features
  • Quickly grasp recipes that work with centralized and decentralized deployments
  • Explore language differences and enhancements anticipated in Puppet version 4
  • Gain expert understanding of Puppet’s latest and most advanced features
  • Step-by-step detailed recipes that help you take control of your servers and desktops
Page Count 336
Course Length 10 hours 4 minutes
ISBN 9781784394882
Date Of Publication 20 Feb 2015

Authors

John Arundel

John Arundel is a DevOps consultant, which means he helps people build world-class web operations teams and infrastructures and has fun doing it. He was formerly a senior operations engineer at global telco Verizon, designing resilient, high-performance infrastructures for major corporations such as Ford, McDonald's, and Bank of America. He is now an independent consultant, working closely with selected clients to deliver web-scale performance and enterprise-grade resilience on a startup budget.

_x000D_

He likes writing books, especially about Puppet (Puppet 2.7 Cookbook and Puppet 3 Cookbook are available from Packt). He also provides training and coaching on Puppet and DevOps, which, it turns out, is far harder than simply doing the work himself.

_x000D_

Off the clock, he is a medal-winning, competitive rifle and pistol shooter and a decidedly uncompetitive piano player. He lives in a small cottage in Cornwall, England and believes, like Cicero, that, if you have a garden and a library, then you have everything you need.

_x000D_

You may like to follow him on Twitter at @bitfield.

Thomas Uphill