Book Image

Mastering Puppet 5

By : Ryan Russell-Yates, Jason Southgate
Book Image

Mastering Puppet 5

By: Ryan Russell-Yates, Jason Southgate

Overview of this book

Puppet is a configuration management system and a language written for and by system administrators to manage a large number of systems efficiently and prevent configuration drift. The core topics this book addresses are Puppet's latest features and mastering Puppet Enterprise. You will begin by writing a new Puppet module, gaining an understanding of the guidelines and style of the Puppet community. Following on from this, you will take advantage of the roles and profiles pattern, and you will learn how to structure your code. Next, you will learn how to extend Puppet and write custom facts, functions, types, and providers in Ruby, and also use the new features of Hiera 5. You will also learn how to configure the new Code Manager component, and how to ensure code is automatically deployed to (multiple) Puppet servers. Next, you will learn how to integrate Puppet with Jenkins and Git to build an effective workflow for multiple teams, and use the new Puppet Tasks feature and the latest Puppet Orchestrator language extensions. Finally, you will learn how to scale and troubleshoot Puppet. By the end of the book, you will be able to deal with problems of scale and exceptions in your code, automate workflows, and support multiple developers working simultaneously.
Table of Contents (19 chapters)
Title Page
Dedication
Packt Upsell
Contributors
Preface
Index

Preface

Puppet 5 remains the software configuration management software of choice, especially for larger-scale configurations.

Here are some examples of current real-world use cases of Puppet:

Although there are newer products, such as Ansible and Salt, Puppet remains – I believe – the premier tool, especially for such larger infrastructures (10,000+ servers). It is worth mentioning that Ansible has also become very popular, possibly due to its shallower learning curve and adoption by Red Hat.

Dealing with this level of scale and complexity is non-trivial. With this book, Mastering Puppet 5, we want to put the know-how at your disposal to tackle your own large-scale challenges, at mastery level.

Version 5 of Puppet, which is the version covered by this book, was announced with considerable fanfare at last year's PuppetConf (2017) by the new CEO, Sanjay Mirchandani, as

"Puppet's largest set of product innovations. Ever."

 In this book, we've gone through these new technologies, including Puppet Discovery, Puppet Tasks, and Puppet Pipelines, to give you the know-how you need to use Puppet 5 in the real world with confidence.

Who this book is for

If you are a system administrator or developer who has already used Puppet and are looking for mastery-level skills and best practices with a view to using Puppet in an enterprise environment, at large scale, this book is for you. Some beginner-level knowledge of using Puppet would be necessary.

 

If you are looking for a gentle introduction to Puppet, before starting to use this book, please take a look at Puppet's own free self-paced training courses (https://learn.puppet.com/category/self-paced-training) or attend some instructor-led or private training (https://puppet.com/support-services/training).

What this book covers

Chapter 1, Authoring Modules, will really get you on the right path to higher quality Puppet modules and manifests, introducing 12 best practices for module writing.

Chapter 2, Roles and Profiles, introduces two additional layers of abstraction and improved interfaces for making your hierarchical business data easier to integrate, making system configurations easier to read, and making refactoring easier.

Chapter 3, Extending Puppet, covers three parts of the ecosystem that can still be accessed at the Ruby level for the purposes of extending Puppet to suit more advanced use cases; namely, custom facts, custom functions, and types and providers. 

Chapter 4, Hiera 5, covers the latest incarnation of Hiera, which allows us to keep all site-specific and business-specific data out of our manifests, making our Puppet modules vastly more portable. We also take a quick look in this chapter at the three layers of configuration and data: globalenvironment, and module. We also cover how to set up an encrypted YAML backend. Lastly, we take a cursory look at using Jerakia to extend Heira.

Chapter 5, Managing Code, covers the use of r10k and Code Manager, allowing us to store all Puppet code in Git repositories and providing version control and rollback capabilities. We discuss directory environments, which give us multiple versions of code on a single master, and how they're supported by r10k and Code Manager. We build a Puppetfile and actively deploy our code to our Puppet Master.

Chapter 6, Workflow, covers a basic Puppet workflow. We'll be incorporating the PDK into our basic workflow more heavily, allowing us to write code more efficiently.

Chapter 7, Continuous Integration, covers tying Puppet into Jenkins as a Continuous Integration (CI) system. We'll discuss the components of a CI/Continue Deployment (CI/CD) pipeline, what it takes to achieve some of the milestones to get there, and actively improve our Puppet code in a CI system.

 

Chapter 8Extending Puppet with Tasks and Discovery, covers Puppet Tasks and Puppet Discovery. Puppet Tasks allows us to run ad hoc commands and use them as building blocks for imperative scripts. We'll be building a task to inspect log files and planning to build an aggregated log file for our Puppet Master. Puppet Discovery allows us to inspect our existing infrastructure and determine ground truth on packages, services, users, and various other components of a virtual machine or container.

Chapter 9, Exported Resources, covers virtual and exported resources in Puppet. We'll explore exporting and collecting resources in our manifests, and the common use cases for exported and collected resources to include the following: a dynamic /etc/hosts file, load balancing, and automatic database connections. We'll also explore the file_line and concat resources to allow us to build dynamic configuration files based on these exported resources.

Chapter 10,Application Orchestration, covers the ordering of multiple node runs. We'll build application orchestration manifests, which allow us to tie nodes together and provide configuration values across multiple nodes, ensuring that our multi-node application runs in the order necessary, with the information it needs.

Chapter 11,Scaling Puppet, covers the horizontal and vertical scaling of Puppet. We'll explore some common settings for tuning, and inspect ways to horizontally scale Puppet services.

Chapter 12,Troubleshooting and Profiling, covers some common troubleshooting cases we see with Puppet. We'll focus on both Puppet service errors and catalog compilation errors, and inspect tuning and configuring our log files.

To get the most out of this book

Users with some prior Puppet experience will get the most out of this book, but every lesson is intended to be helpful to someone at any stage of learning about Puppet. To follow along in the book, users should install a trial version of Puppet Enterprise and attach some nodes to the Puppet Master. Each chapter will help set up the Puppet Master in a way to utilize the existing infrastructure.

Directions for installing Puppet Enterprise can be found at https://puppet.com/docs/pe/latest/installing_pe.html

 

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packt.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Mastering-Puppet-5. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://www.packtpub.com/sites/default/files/downloads/9781788831864_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "The earlier incarnations of Hiera (version 3 or earlier) used a single, entirely global hiera.yaml."

A block of code is set as follows:

lookup({
   'name'  => 'classification',
   'merge' => {
     'strategy'        => 'deep',
     'knockout_prefix' => '--',
   },
 })

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

lookup({
   'name'  => 'classification',
   'merge' => {
'strategy' => 'deep',
     'knockout_prefix' => '--',
   },
 })

Any command-line input or output is written as follows:

$ sudo /opt/puppetlabs/puppet/bin/gem install hiera-eyaml

Bold: Indicates a new term, an important word, or words that you see on screen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "We can reach the plugin page by clicking on Manage Jenkins on the left-hand side of the screen."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.