Home » Puppet Classes

Puppet Classes

Puppet classes are the set of puppet resources that are grouped together as a single unit. Classes are used to model the fundamental aspects of the node. Puppet uses classes to make the structure reusable and organized. Classes can only be evaluated once per node.

Classes are described within the manifest file, located inside Puppet modules. The main reason for using a class is to decrease the duplication of the same code inside any manifest file or other puppet code.

Defining a Class

Before using a class, we have to define it, which is done by the class keyword, the name of the class, curly braces, and a set of code. This part of the code does not automatically evaluate the code.

Syntax:

Declaring a Class

The declaration part of a class evaluates the code in the class and applies all its resources. This part of the code actually does something.

Syntax:

Let’s see another simple example which is similar to the above example:

Parameterized Class

Parameters are used to allow a class to request external data. If a class has to configure itself to data other than facts, the data will typically be inserted by a parameter into the class.

Let’s see one example:

In the above example, we created a class windows_ntp, which grouped together a registry resource and a service resource to configure the Windows time service. windows_ntp class accepts the time server address as a parameter named $server.


Next TopicPuppet Function

You may also like