Using the type system

Older Puppet versions supported a small set of data types only: Bool, String, Array, and Hash. The Puppet DSL had almost no functionality to check for consistent variable types. Consider the following scenario.

A parameterized class enables other users of your code base to change the behavior and output of the class:

class ssh (  $server = true,){  if $server {    include ssh::server  }}

This class definition checks whether the server parameter has been set to true. However, in this example, the class was not protected from wrong data usage:

class { 'ssh': 
  server => 'false', 
} 

In this class declaration, the server parameter has been given a string instead of a bool value. Since the false string is not empty, the if $server ...

Get Puppet 5 Essentials - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.