Puppet Modules
• Modules are self-contained bundles of code and data with a specific directory structure
• These reusable, shareable units of Puppet code are a basic building block for Puppet
• Modules must have a valid name and be located in modulepath
• Puppet automatically loads all content from every module in modulepath making classes, defined types, and plug-ins (such as custom types or facts) available
• You can download and install modules written by Puppet or the Puppet community from the Puppet Forge
Module Structure
• Modules have a specific directory structure that allows Puppet to find and automatically load classes, defined types, facts, custom types and providers, functions, and tasks
• Module names should contain only lowercase letters, numbers, and underscores, and should begin with a lowercase letter
• Each manifest in a module’s manifests folder should contain only one class or defined type
• You can serve files in a module’s files directory to agent nodes
• Any ERB or EPP template can be rendered in a manifest
Exercise - Puppet Modules
Go to master terminal window and run the following command
cd /etc/puppet/modules
puppet module generate reuseable-module
This will start guiding you how to create your module. Leave source code repository blank and generate the meta data required for module.
Go to the master terminal and under folder /etc/puppet/modules/reuseable-module. You will see a lot of files that support the development of your module
Go to the folder /etc/puppet/modules/reuseable-module/manifests. In that you will see an init.pp. Edit this file
nano init.pp
class reuseable-module {
notify {“This is the reusable module”: }
}
Go to the master terminal and /etc/puppet/modules/reusable-module/tests. Edit the init.pp file in this folder
include reuseable-module
Close the file and go to tests folder under the module reusable-module and open init.pp and apply from this folder
include reuseable-module
puppet apply init.pp
Next we will download a module from Puppet Forge and apply it to agent
Go to Puppet Forge and search for module apache. Download it to /etc/puppet/modules folder on Puppet Master by using following command
puppet module install puppetlabs-apache --version 2.3.0
This will create 3 folders – apache, concat and stdlib under your modules folders
Go back to your reusable-module and under manifests open the init.pp file and add the following code to the class
include apache
Now go to the test folder and run
puppet apply init.pp
This will install apache on the master
Comments
Post a Comment