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
condition ...
Get Puppet: Mastering Infrastructure Automation now with the O’Reilly learning platform.
O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.