
Puppet 4 Essentials, Second Edition
By :

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 actually passes. This is not what the user will expect.
Within Puppet 3, it was recommended to add parameter validation using several functions from the stdlib
module:
class ssh ( $server = true, ){ validate_bool($server) if $server...
Change the font size
Change margin width
Change background colour