
Puppet 4 Essentials, Second Edition
By :

Puppet's equivalents to methods or functions are twofold: there are classes on one hand and defined types (also just referred to as defines) on the other.
You will find that the function analogy is a bit weak for classes, but fits defined types quite well.
They are similar at first glance, in that they both hold a chunk of reusable manifest code. There are big differences in the way each is used though. Let's take a look at classes first.
A Puppet class can be considered to be a container for resources. It is defined once and selected by all nodes that need to make use of the prepared functionality. Each class represents a well-known subset of a system's configuration.
For example, a classic use case is a class that installs the Apache web server and applies some basic settings. This class will look like the following:
class apache { package { 'apache2': ensure => 'installed', } file { '/etc/apache2/apache2.conf...
Change the font size
Change margin width
Change background colour