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

Chapter 1. Authoring Modules

Authoring Puppet modules and manifests is the real heart of the work for your Puppet ecosystem.

So, you've perhaps already written at least a few modules for software components in your infrastructure, and there's already a great guide to getting started writing modules in the Puppet documentation at https://puppet.com/docs/pe/2017.3/quick_start_guides/writing_modules_nix_getting_started_guide.html, so I won't waste any time going over that material again. But I'm sure that, in pursuit of mastering Puppet v5, what you would really like to do is to write those modules correctly.

Let's take that step together toward better quality modules in this chapter. I've spent a lot of time in the trenches over the last few years, gathering together best practices from some of the best projects across Europe and applying practices and software principles I've learned from both my university education and 15+ years in the industry. I hope I can introduce you to some shortcuts and make your life easier!

The following are a set of recommendations that I feel will really get you on the right path to higher quality Puppet modules and manifests:

  • Using a decent IDE and plugins
  • Using a good module class structure:
    • Following the class-naming conventions
    • Having a single point of entry to the module
    • Using high cohesion and loose coupling principles
    • Using the encapsulation principle
    • Strongly typing your module variables

 

  • Using the new Puppet Development Kit commands:
    • Creating the module framework and metadata
    • Creating the init.pp
    • Creating further classes
    • Validating your module
    • Unit testing your module
  • Staying on the lookout for code smells
  • Making sure you are not working with dead code
  • Working with the community
  • Using Puppet Forge
  • Writing great documentation
  • Adding module dependencies
  • Adding compatibility data for your modules
    • Operating systems support
    • Puppet and PE version support
  • Using the new Hiera 5 module level data
  • Upgrading your templates from ERB to ERP syntax

Let's examine each of these best practices now in turn.