We've seen classes before, when we used the class
keyword to group together the Puppet resources that implement some particular service, such as Nginx:
# Manage nginx webserver class nginx { package { 'nginx': ensure => installed, } }
The class
keyword introduces a new class definition:
class nginx { ... }
You can also specify some parameters that the class accepts:
class appserver($domain,$database) { ... }
The parameters can take default values, as with a definition:
class hadoop($role = 'node') { ... }
It's a good idea to organize your classes into modules, just as we did with the nginx
class. Each class should be stored in the modules/MODULE_NAME/manifests
directory, in a file named after the class, with each file containing just one class.
So if we create an nginx::loadbalancer
class, the definition should look like this:
class nginx::loadbalancer { ... }
It should go in the file modules/nginx/manifests/loadbalancer.pp
.
The...