Saturday, January 11, 2014

Basic Puppet Programs - Manifest

Basically, puppet programs are called “manifests,” and they use the .pp file extension.

site.pp: first file that the Puppet Master parses when determining a server’s catalog. It imports all the underlying subdirectories and the other special files in this directory. It also defines any global defaults, such as package managers as per http://projects.puppetlabs.com/projects/1/wiki/Puppet_Best_Practice2

To begin with, lets start definining things in the first file that the puppet master parses.

site.pp file should contain all the nodes -- clients as well as master, else it will not allow to proceed further.

On master server - CentOS

Create file - /etc/puppet/manifests/site.pp


node 'server.puppet.com' {
    }

node 'client1.puppet.com', 'client2.puppet.com' {
     }

Now, lets move further and introduce packages that we need to install on clients.

Now that we have clients on Ubuntu, we need to define operating system variable with a switch.


Packages to be installed - nmap and elinks.

Edit file /etc/puppet/manifests/site.pp


node 'server.puppet.com' {
    }

node 'client1.puppet.com', 'client2.puppet.com' {
      include nmap
      include elinks
    }

class nmap {
case $operatingsystem {
        centos, redhat: {
        package { "nmap":
        ensure => installed,
        }
      }
        debian, ubuntu: {
        package { "nmap":
        ensure => installed,
        }
      }
     }
    }

class elinks {
case $operatingsystem {
        centos, redhat: {
        package { "elinks":
        ensure => installed,
        }
      }
        debian, ubuntu: {
        package { "elinks":
        ensure => installed,
        }
      }
     }
    }

Note : If you can see in the above code in nodes section, we have included nmap and elinks class in clients and not in master. And in below section defined both the classes.

Apply changes on the master to take effect.


puppet apply -v  /etc/puppet/manifests/site.pp
info: Applying configuration version '1389452030'
notice: Finished catalog run in 2.43 seconds


Let move on to client to fetch changes.

On client server : Ubuntu


puppet agent -v --test
info: Caching catalog for client2.puppet.com
info: Applying configuration version '1389452959'
notice: /Stage[main]/Elinks/Package[elinks]/ensure: created
notice: /Stage[main]/Nmap/Package[nmap]/ensure: ensure changed 'purged' to 'present'
notice: Finished catalog run in 16.69 seconds


Note : Client synchronizes every 30 minutes for any changes/configuration applied on the puppet master server.


1 comment: