*Modules in puppet*
Modules are a way of arranging manifests/files/templates in puppet. Why they are arranged like this?? So that they can be automatically called by the puppet master when needed.
What is the location of module??
- Default location, you can find it by firing below command:
[root@puppet modules]# puppet master --genconfig | grep modulepath
modulepath = /etc/puppet/modules:/usr/share/puppet/modules
[root@puppet modules]#
- User defined location, If in-case you want to use the user defined location to fetch the modules so that puppet master can use it you need to use a option called --modulepath while firing the command.
[root@puppet manifests]# puppet apply site.pp --modulepath=/tmp/mods/
notice: Finished catalog run in 0.26 seconds
[root@puppet manifests]#
Structure of a module:
modules/
└── ntp
├── files
│ ├── ntp.conf.debian
│ └── ntp.conf.el
├── manifests
│ └── init.pp
└── templates
├── ntp.conf.debian.erb
└── ntp.conf.el.erb
In the above example you can see the parent directory is modules/, under that there one directory called ntp/ [that's our module] under which there are 3 directories called files/ , manifests/ , templates/ which includes there respective files.
files/: It contains static files, which the managed agent nodes can download to get themselves to their desired state. In this case there are ntp.conf.debian[Ubuntu/Kubuntu/Debian] and ntp.conf.el [RedHat/Fedora/CentOS].
templates/: It contains dynamic files, which can be used by the manifests [indirectly by the puppet master] to create a config file so that those files can be used by the agent nodes to get themselves to their desired state. In this case there are ntp.conf.debian.erb[Ubuntu/Kubuntu/Debian] and ntp.conf.el.erb [RedHat/Fedora/CentOS].
- ERB is a feature of Ruby that enables you to create any kind of text from templates.
manifests/: The most important directory of the module without this your module is really of no use. It contains all the .pp files which are relevant for a module. Most importantly it should have a init.pp.
It contains one class named
[YOUR MODULE NAME]
and this class’s name must match the module’s name. So suppose in this case my module's name is ntp so there must be a class called ntp in init.pp file.
[root@puppet puppet]# cat modules/ntp/manifests/init.pp
class ntp {
case $operatingsystem {
CentOS , RedHat , Fedora: {
$service_name = 'ntpd'
...........
...........
...........
subscribe => File['ntp.conf'],
}
}
[root@puppet puppet]#
There are various important modules which are supplied by "The Puppet Forge" you can get them downloaded and use it.
By below command you can search the modules which are there in puppet forge and get them installed:
[root@puppet puppet]# puppet module search httpd
Searching http://forge.puppetlabs.com ...
NAME DESCRIPTION AUTHOR KEYWORDS
.............
............. httpd mod_jk tomcat apache @domcleal ssh nrpe sshd host grub httpd
eshamow-pe_httpd UNKNOWN @eshamow
example42-lighttpd Puppet module for lighttpd @example42
.............
............. lighttpd webserver example42 @proudsourcing php5 ioncube debian httpd oxid
puppetlabs-apache Puppet module for Apache @puppetlabs web httpd rhel ssl wsgi proxy
.............
.............
[root@puppet puppet]#
Now suppose you want to install the apache module provided by puppetlabs.
[root@puppet puppet]# puppet module install puppetlabs-apache
Preparing to install into /etc/puppet/modules ...
Downloading from http://forge.puppetlabs.com ...
Installing -- do not interrupt ...
/etc/puppet/modules
└─┬ puppetlabs-apache (v1.1.1)
├── puppetlabs-concat (v1.1.0)
└── puppetlabs-stdlib (v4.3.2)
[root@puppet puppet]#
Or if you want to uninstall it use the option uninstall and it will be removed.
[root@puppet apache]# puppet module uninstall puppetlabs-apache
Preparing to uninstall 'puppetlabs-apache' ...
Removed 'puppetlabs-apache' (v1.1.1) from /etc/puppet/modules
[root@puppet apache]#
How to create a puppet module???
Comments
Post a Comment