- Mastering Puppet 5
- Ryan Russell Yates Jason Southgate
- 95字
- 2021-07-16 17:46:07
Strongly typing your module variables
In versions of Puppet proper to the new language features which came out in version 4, we would create class parameters with undefined data types, and then, if we were being very nice, we would use the stdlib validate_<datatype> functions to check appropriate values for those variables:
class vhost (
$servername,
$serveraliases,
$port
)
{ ...
Puppet 4 and 5 have an in-built way of defining the data type that a parameterized class accepts. See the following example:
class vhost (
String $servername,
Array $serveraliases,
Integer $port
)
{ ...