Understanding Puppet Modules

Using Modules

Modules are self-contained bundles of code and data. You can download pre-built modules from the Puppet Forge or you can write your own modules .

Modules are how Puppet finds the classes and types it can use — it automatically loads any class or defined type stored in its modules. Any of these classes or defines can be declared by name within a manifest or from an external node classifier (ENC) . 

Module layout

On disk, a module is simply a directory tree with a specific, predictable structure:
    • manifests
    • files
    • templates
    • lib
    • facts.d
    • examples
    • spec
     
  • files/ — Contains static files, which managed nodes can download.
    service.conf — This file’s source => URL would be puppet:///modules/my_module/service.conf. Its contents can also be accessed with the file function, like content => file('my_module/service.conf'). Puppet will be looking for service.conf in  ${codedir}/environments/production/modules/my_module/files/service.conf
  • templates/-- Contains templates, which the module’s manifests can use. Templates can be
       component.erb — A manifest can render this template     
                   with template('my_module/component.erb').
       component.epp — A manifest can render this template with   
                             epp('my_module/component.epp').


Examples of  Using Modules: 
 
  • Files:
      file {"/home/agile/app.properties":
              path =>"/home/agile/app.properties",
              ensure => present,
              owner => agile,
              group => agile,
              source => "puppet:///modules/puppe/app.properties",
            }


In the above example, app.properties should be placed in $modulepath/puppet/files/ directory


  • Templates:    
       file { "/etc/hosts":
            ensure => present,
            owner => root,
            group => root,
            content  => template("puppet/${fqdn}/hosts.erb"),
           }


In the above example , hosts.erb should be placed in $modulepath/puppet/templates/ directory. 



What is an ENC

An external node classifier is an executable that can be called by puppet master. Its only argument is the name of the node to be classified, and it returns a YAML document describing the node.
Inside the ENC, you can reference any data source you want, including some of Puppet’s own data sources, but from Puppet’s perspective, it just puts in a node name and gets back a hash of information.

Example:

# cat /apps/wps/puppetlabs/code/environments/production/modules/puppet/templates//hosts.erb

      127.0.0.1              localhost localhost.localdomain 

      <%= @ipaddress %>      <%= @hostname %>
      <%= @ipaddress %>      <%= @fqdn %>


In the above example , 


   <%= @ipaddress %>  :IP Address of Server  (10.201.32.X)
   <%= @fqdn %>       :FQDN of  Server  (server1.example.com)

This will generate host file as follows:

      127.0.0.1                localhost localhost.localdomain       10.201.32.X              server1
      10.201.32.X              server1.example.com  





       

                                                     

Comments

Popular posts from this blog

PSSH : Parallel SSH to execute commands on a number of hosts

How to add check_http as a service in Nagios Monitoring using NRPE

Configuring Nagios to monitor services using NRPE