Go to main content

Using Puppet to Perform Configuration Management in Oracle® Solaris 11.4

Exit Print View

Updated: October 2019

Writing Puppet Classes

Classes are blocks of Puppet code that enable reuse. Using classes makes reading manifests less complicated. A class definition contains the code for a specific class. You first define the class, then you make the class available for use within manifests. Note that the class itself does not perform any evaluation.

The following example shows the format that is used for a class definition named examplecloud:

class examplecloud::analytics {

    package { "system/management/webui/webui-server":
        ensure => installed,

    svccfg { "webui":
        require => Package["system/management/webui/webui-server"],
        fmri => "system/webui/server:default",
        property => "conf/redirect_from_https",
        value => "false",
        ensure => present,

    service { "system/webui/server":
        require => Package["system/management/webui/webui-server"],
        ensure => running,


In this example, the class has two name spaces: examplecloud and analytics. The code that is specified in this class ensures that certain IPS packages are installed and that certain SMF configuration is applied prior to enabling the analytics SMF service on the node.

A class declaration is a class that is defined within a manifest. A class declaration instructs Puppet to evaluate the code within that class.

    Puppet defines two types of class declarations: normal and resource-like.

  • For the normal class declaration, the include keyword is included in Puppet code, as shown in the following example:

    include example_class
  • For the resource-type class declaration, the class is declared similarly to how a resource is declared, as shown in this example:

    class { 'example_class': }

    You use resource-like class declarations to specify class parameters. These parameters override the default values of class attributes.

For more in-depth information about writing and assigning Puppet classes, go to https://puppet.com/docs/puppet/5.5/lang_classes.html.

Example 3  Including a Class Declaration in a Puppet Manifest

The following example manifest uses a class declaration named examplecloud, which is located in the /etc/puppetlabs/code/modules directory on the Puppet master.

Under the examplecloud class are several manifests (/etc/puppetlabs/code/modules/examplecloud/manifests) that specify various configurations. Each manifest includes the examplecloud class declaration, as shown in the following example:

# NTP configuration for companyfoo
class examplecloud::ntp {

    file { "ntp.conf" :
        path => "/etc/inet/ntp.conf",
        owner => "root",
        group => "root",
        mode => 644,
        source => "puppet:///modules/examplecloud/ntp.conf",

    package { "ntp":
        ensure => installed,

    service { "ntp":
        require => File["ntp.conf"],
        subscribe => File["ntp.conf"],
        ensure => running,


    The declarations for the examplecloud class in the preceding example ensure the following:

  • The NTP package is installed

  • A certain configuration file (which is sourced from a location other than the Puppet master) is installed

  • The NTP service is enabled and in a running state on the node