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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.253.221