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

Unit testing with Puppet RSpec


Unit testing is testing focused around the smallest unit of code. In the case of Puppet, the smallest functional unit of code is the manifest. RSpec provides us with a unit testing framework for Puppet code, which is fast and effective at checking that our Puppet code is producing the Puppet catalogs we expect. Whatever tests we write in RSpec, we're essentially asking: would what I want be in the Puppet catalog when I execute this code?

 

RSpec as a system is run on the command line, and does not involve a new virtual machine or container. It is now included in the Puppet PDK under the command pdk test unit. We're going to look at the files involved in running unit tests, and writing simple unit tests from the templates provided by the PDK.

We're beginning a new feature set, so we'll want to start from master, pull down the remote commits, and start on a new branch:

[rary@workstation profile]# git checkout master
Switched to branch 'master'

[rary@workstation...