Site icon UnixArena

Puppet – Puppet Forge Modules – Overview

Puppet Forge Modules

Puppet Forge Modules

Puppet forge is a module repository for  Puppet Open Source and Puppet Enterprise IT automation software. These modules are written by puppet community members and puppet reviews the module before publishing it. Puppet also supports many of modules in this repository.  Why do we require pre-built puppet modules ?  To simply system administrator work and reduce the coding effort. These pre-built codes will  help you to automate most of the things in short time. In this article ,we will install LVM module from puppet forge and apply it in our environment.

 

Install Puppet Module from Puppet Forge:

LVM module provides Puppet types and providers to manage Logical Resource Management (LVM) features. This module provides four resource types (and associated providers): volume_group, logical_volume, physical_volume, and filesystem. The basic dependency graph needed to define a working logical volume looks something like:

[box type=”shadow” align=”” class=”” width=””] Filesystem -> logical_volume -> volume_group -> physical_volume(s)[/box]

 

1.Login to the puppet server as root and install the LVM module.

[root@UA-HA manifests]# puppet module install puppetlabs-lvm
Notice: Preparing to install into /etc/puppetlabs/code/environments/production/modules ...
Notice: Downloading from https://forgeapi.puppetlabs.com ...
Notice: Installing -- do not interrupt ...
/etc/puppetlabs/code/environments/production/modules
└─┬ puppetlabs-lvm (v0.7.0)
  └── puppetlabs-stdlib (v4.11.0)
[root@UA-HA manifests]#

You will get the exact command from puppet forge to install specific modules.

 

2.Navigate to the LVM’s module  directory.

[root@UA-HA manifests]# cd /etc/puppetlabs/code/environments/production/modules
[root@UA-HA modules]# ls -lrt
total 8
drwxr-xr-x 6 root root 4096 Jan 12 06:08 stdlib
drwxr-xr-x 5 root root 4096 Jan 14 06:35 lvm
drwxr-xr-x 3 root root   22 Feb  8 14:16 helloworld
drwxr-xr-x 6 root root   65 Feb  8 15:15 accounts
drwxr-xr-x 6 root root   65 Feb 10 23:36 httpd
drwxr-xr-x 5 root root   50 Feb 14 07:18 ntpconfig
drwxr-xr-x 5 root root   50 Feb 14 09:02 filetest
drwxr-xr-x 5 root root   50 Feb 14 10:55 testdirs
drwxr-xr-x 5 root root   50 Feb 15 14:11 sshdroot
drwxr-xr-x 5 root root   50 Feb 16 02:01 apachehttpd
[root@UA-HA modules]# cd lvm
[root@UA-HA lvm]# ls -lrt
total 56
-rw-r--r-- 1 root root 11368 Jan 14 05:30 README.md
-rw-r--r-- 1 root root   662 Jan 14 05:30 Rakefile
-rw-r--r-- 1 root root 17987 Jan 14 05:30 LICENSE
-rw-r--r-- 1 root root   539 Jan 14 05:30 Gemfile
-rw-r--r-- 1 root root  4251 Jan 14 05:30 CHANGELOG.md
drwxr-xr-x 4 root root    48 Jan 14 06:35 spec
-rw-r--r-- 1 root root  1102 Jan 14 06:35 metadata.json
-rw-r--r-- 1 root root  2854 Jan 14 06:35 checksums.json
drwxr-xr-x 2 root root    82 Feb 16 02:57 manifests
drwxr-xr-x 4 root root    32 Feb 16 02:57 lib
[root@UA-HA lvm]# cd manifests/
[root@UA-HA manifests]#

 

3. Navigate to the manifest directory and review the current puppet code.

[root@UA-HA lvm]# cd manifests/
[root@UA-HA manifests]# ls -lrt
total 24
-rw-r--r-- 1 root root 4386 Jan 14 05:30 volume.pp
-rw-r--r-- 1 root root  585 Jan 14 05:30 volume_group.pp
-rw-r--r-- 1 root root 3583 Jan 14 05:30 logical_volume.pp
-rw-r--r-- 1 root root  130 Feb 16 03:03 init.pp
[root@UA-HA manifests]#
[root@UA-HA manifests]# cat volume.pp
[root@UA-HA manifests]# cat volume_group.pp
[root@UA-HA manifests]# cat logical_volume.pp
[root@UA-HA manifests]# cat init.pp

These manifest contains the sample codes. You can safely rename the “init.pp” as “init.pp.old” and starting writing custom code.

 

4. You should know what LUN is free on the puppet agent nodes before writing your own manifest. In my case, “/dev/sdb” is free disk.

[root@UA-HA manifests]# cat init.pp
class lvm {

lvm::volume { 'ualv1':
  ensure => present,
  vg     => 'uavg',
  pv     => '/dev/sdb',
  fstype => 'ext3',
  size   => '100M',
}

}
[root@UA-HA manifests]#

This code will automatically create the volume group , logical volume and ext3 filesystem on that.

 

5. Navigate back to main manifest directory and edit nodes.pp file to call LVM module for puppet agent node “uapa1”.

[root@UA-HA manifests]# cd ../../../manifests/
[root@UA-HA manifests]# cat nodes.pp
node uapa1 {
  include lvm
}
[root@UA-HA manifests]#

 

6.Login to puppet agent node(uapa1) and check the current LVM configuration.

[root@uapa1 ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 536 MB, 536870912 bytes, 1048576 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@uapa1 ~]# vgs
  VG   #PV #LV #SN Attr   VSize   VFree
  rhel   1   2   0 wz--n-  19.51g      0
[root@uapa1 ~]# lvs
  LV    VG   Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root  rhel -wi-ao----  17.51g
  swap  rhel -wi-ao----   2.00g
  [root@uapa1 ~]#

 

7. Run the puppet agent test to apply the configuration immediately. (Puppet agent automatically applies the new configuration for every 30mins)

[root@uapa1 ~]# puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for uapa1
Info: Applying configuration version '1455609925'
Notice: /Stage[main]/Lvm/Lvm::Volume[ualv1]/Physical_volume[/dev/sdb]/ensure: created
Notice: /Stage[main]/Lvm/Lvm::Volume[ualv1]/Volume_group[uavg]/ensure: created
Notice: /Stage[main]/Lvm/Lvm::Volume[ualv1]/Logical_volume[ualv1]/ensure: created
Notice: /Stage[main]/Lvm/Lvm::Volume[ualv1]/Filesystem[/dev/uavg/ualv1]/ensure: created
Notice: Applied catalog in 8.09 seconds
[root@uapa1 ~]#

 

8.Verify our work .

[root@uapa1 ~]# vgs uavg
  VG   #PV #LV #SN Attr   VSize   VFree
  uavg   1   1   0 wz--n- 508.00m 408.00m
[root@uapa1 ~]# lvs -o +devices
  LV    VG   Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert Devices
  root  rhel -wi-ao----  17.51g                                                     /dev/sda2(512)
  swap  rhel -wi-ao----   2.00g                                                     /dev/sda2(0)
  ualv1 uavg -wi-a----- 100.00m                                                     /dev/sdb(0)
[root@uapa1 ~]#

 

Here we can see that “uavg” volume group and “ualv1” logical volume have been created successfully. This is how you need to install the pre-built module from puppet forge and tweak it according to your environment.

 

Hope this article informative to you . Share it ! Comment it !! Be Sociable !!!

 

Exit mobile version