Go to main content

Using Puppet to Perform Configuration Management in Oracle® Solaris 11.3

Exit Print View

Updated: September 2018

Writing Puppet Modules

Puppet modules are a collection of manifests and data, which can include facts, files, and templates. Modules help you organize and reuse Puppet code by enabling you to split the code into several manifests. With the exception of the main site.pp manifest that contains global configuration for all of the nodes, nearly all Puppet manifests should be included in modules. If you have several Puppet manifests, consider using modules as a way to organize them.


Caution  -  Modules that are provided through IPS are specifically updated for Oracle Solaris. Do not replace these modules with Puppet Forge modules.

To write your own Puppet module, you would start by running the following command on the Puppet master:

# puppet module generate module-name

Running the previous command prompts you with a series of questions. Puppet uses your responses to gather information about the module and then creates a basic module structure. For further instructions and examples, see Writing Modules.

You add Puppet modules that you create to the /etc/puppet/modules directory on the master, where the basic directory tree structure is similar to the following:

module-name/ – Is the outermost (or parent) directory structure that specifies the name of the module.

  • manifests/ – Contains all of the manifests within the module.

    • init.pp – Contains a class definition. The name of the class definition must match the name of the module.

    • other_class.pp – Contains a defined type named my_module::my_defined_type.

    • my_defined_type.pp – Contains a class named my_module::other_class.

    • my_module::my_defined_type – Contains a defined type named my_module::my_defined_type.

    • implementation/ – Is a directory with a name that affects the class names that are stored under it.

      • foo.pp – Contains a class named my_module::implementation::foo.

      • bar.pp – Contains a class named my_module::implementation::bar.

  • files/ – Contains static files that managed nodes can download.

    service.conf – Is a file with a source URL that is similar to puppet:///modules/my_module/service.conf. You can access the file's contents by using a file function, for example, my_module/service.conf.

  • lib/ – Contains plug-ins, for example custom facts and resource types, which are used by both the Puppet master server and the Puppet agent service.

  • facts.d/ – Contains external facts, which you can use as an alternative to Ruby-based custom facts.

  • templates/ – Contains templates that a module’s manifests can use.

    • component.erb – Is a template that a manifest can render as my_module/component.erb.

    • component.epp – Is a template that a manifest can render as my_module/component.epp.

  • examples/ – Contains examples that show how to declare the module’s classes and defined types.

    • init.pp

    • other_example.pp – Includes major use case examples.

  • spec/ – Contains tests for any plug-ins that are in the lib directory.

As shown in the following example, a module named examplecloud is located under the /etc/puppet/modules directory:

# cd /etc/puppet/modules
# ls -al
drwxrwxr-x   3 userfoo   staff          3 Mar  4 14:44 .
drwxr-xr-x   5 userfoo   staff          6 Mar 25 06:33 ..
drwxr-xr-x   4 userfoo   staff          4 Mar  3 13:24 examplecloud
# cd examplecloud
# ls -al
drwxr-xr-x   4 userfoo   staff          4 Mar  3 13:24 .
drwxrwxr-x   3 userfoo   staff          3 Mar  4 14:44 ..
drwxr-xr-x   3 userfoo   staff         12 Mar  9 11:55 files
drwxr-xr-x   2 userfoo   staff         12 Mar 24 15:43 manifests

Under the examplecloud directory is the manifests directory that contains the manifests for the module. Each manifest contains one class or defined type, as shown in the following output:

# cd /etc/puppet/modules/examplecloud/manifests
# ls -al
total 52
drwxr-xr-x   2 userfoo   staff         12 Mar 24 15:43 .
drwxr-xr-x   4 userfoo   staff          4 Mar  3 13:24 ..
-rw-r--r--   1 userfoo   staff        552 Mar  3 13:24 analytics.pp
-rw-r--r--   1 userfoo   staff       1097 Mar  3 13:24 compute_node.pp
-rw-r--r--   1 userfoo   staff       1232 Mar  7 12:45 dlmp_aggr.pp
-rw-r--r--   1 userfoo   staff        491 Mar  3 13:24 mysql.pp
-rw-r--r--   1 userfoo   staff       1764 Mar  7 12:45 nameservice.pp
-rw-r--r--   1 userfoo   staff       1073 Mar 24 15:43 neutron_aggr.pp
-rw-r--r--   1 userfoo   staff        463 Mar  3 13:24 ntp.pp
-rw-r--r--   1 userfoo   staff       1814 Mar  3 13:24 openstack_horizon.pp
-rw-r--r--   1 userfoo   staff        690 Mar  3 13:24 rabbitmq.pp
-rw-r--r--   1 userfoo   staff       1688 Mar 14 14:34 storage_ip.pp 

Manifest file names map to the names of the classes and defined types that they contain. Each subdirectory under the examplecloud/manifests directory has a specific function.

For a more comprehensive description of each of these components, go to Module Fundamentals.

The Puppet Forge site includes a repository of publicly available modules, including newer modules, as well as authoring tools and documentation that you can download.