Puppet 3 Cookbook

Puppet 3 Cookbook

John Arundel

Language: English

Pages: 274

ISBN: 1782169768

Format: PDF / Kindle (mobi) / ePub

Build reliable, scalable, secure, and high-performance systems to fully utilize the power of cloud computing


  • Use Puppet 3 to take control of your servers and desktops, with detailed step-by-step instructions
  • Covers all the popular tools and frameworks used with Puppet: Dashboard, Foreman, MCollective, and more
  • Teaches you how to extend Puppet with custom functions, types, and providers
  • Packed with tips and inspiring ideas for using Puppet to automate server builds, deployments, and workflows

In Detail

A revolution is happening in web operations. Configuration management tools can build servers in seconds, and automate your entire network. Tools like Puppet are essential to taking full advantage of the power of cloud computing, and building reliable, scalable, secure, high-performance systems. More and more systems administration and IT jobs require some knowledge of configuration management, and specifically Puppet.

"Puppet 3 Cookbook" takes you beyond the basics to explore the full power of Puppet, showing you in detail how to tackle a variety of real-world problems and applications. At every step it shows you exactly what commands you need to type, and includes full code samples for every recipe.

The book takes the reader from a basic knowledge of Puppet to a complete and expert understanding of Puppet’s latest and most advanced features, community best practices, writing great manifests, scaling and performance, and extending Puppet by adding your own providers and resources. It starts with guidance on how to set up and expand your Puppet infrastructure, then progresses through detailed information on the language and features, external tools, reporting, monitoring, and troubleshooting, and concludes with many specific recipes for managing popular applications.

The book includes real examples from production systems and techniques that are in use in some of the world’s largest Puppet installations, including a distributed Puppet architecture based on the Git version control system. It covers common problems and errors and shows you how to troubleshoot your Puppet manifests. You’ll be introduced to powerful tools that work with Puppet such as Hiera and MCollective. You’ll learn how to use objection orientation and classes to write powerful, reusable manifests, and how to embed Ruby code in templates. You’ll find out how to extend Puppet with custom resource types and providers. The book also explains managing Rails applications and databases, building web servers, load balancers, high-availability systems with Heartbeat, and many other state-of-the-art techniques.

What you will learn from this book

  • Install and set up Puppet for the first time
  • Manage large networks with tools like Foreman and MCollective
  • Take control of configuration data with Hiera and encrypting secrets with GnuPG
  • Produce reliable, clean, maintainable code to community standards with puppet-lint and rspec-puppet
  • Use classes and inheritance to write powerful Puppet code
  • Deploy configuration files and templates for lightning-fast installations
  • Use virtual machines to build test and staging environments, and production systems on cloud platforms such as EC2
  • Automate every aspect of your systems including provisioning, deployment, and change management














directly by name using an @ prefix, if they are in the current scope: <%= @name %> If they are in another scope you can reference them using scope.lookupvar, as follows: <%= "The variable from otherclass is " + scope.lookupvar('otherclass::variable') %> You should use inline templates sparingly. If you really need to do some complicated logic in your manifest, consider using a custom function instead (see the Creating custom functions section in Chapter 8, External tools and the Puppet

inheritance and overriding 75 Writing reusable, cross-platform manifests 79 Getting information about the environment 81 Importing dynamic information 83 Passing arguments to shell commands 84 Introduction 87 Making quick edits to config files 88 Using Augeas to automatically edit config files 89 Building config files using snippets 91 Using ERB templates 94 Using array iteration in templates 96 Using GnuPG to encrypt secrets 98 Installing packages from a third-party repository 103

Beware of accidentally introducing dependency cycles, though; when you assign something to a run stage you're automatically making it dependent on everything in prior stages. You may like to define your stages in the site.pp file instead, so that it's easy to see at the top level of the manifest what stages are available. Gary Larizza has written a helpful introduction to using run stages, with some real-world examples, on his website:

net.ipv4.ip_forward = 1 How it works… We declare an augeas resource named enable-ip-forwarding: augeas { 'enable-ip-forwarding': We specify that we want to make changes in the context of the file /etc/sysctl.conf: context => '/files/etc/sysctl.conf', The changes parameter specifies the changes we want to make. Its value is an array, because we can supply several changes at once. In this example, there is only change, so the value is an array of one element: changes => ['set net.ipv4.ip_forward

of a code block, the relevant lines or items are set in bold: newparam(:path) do validate do |value| basepath = File.dirname(value) unless File.directory?(basepath) raise ArgumentError , "The path %s doesn't exist" % basepath end end end 3 Preface Any command-line input or output is written as follows: ubuntu@cookbook:~/puppet$ papply Notice: Hello, I was included by your ENC! Notice: /Stage[main]/Admin::Helloenc/Notify[Hello, I was included by your ENC!]/message: defined 'message' as 'Hello,

Download sample