Sunday, October 15, 2017

learn how to use facter in puppet.

=====================================================
Following practical will help you to know how to use facter in puppet.
=====================================================

Facter is command tool which provides the node specific information, which is used by puppet master for node segregation of spacfic content managment


[root@pupprdclt1 ~]# facter | egrep "family | hostname|kernelversion"
kernelversion => 2.6.32
  hostname => "pupprdclt1",
  family => "RedHat",
[root@pupprdclt1

===================================================================
Check squid is not installed on puppet agent node, and we will use above mentioned facters in manifest on master server for the code deployment.
 ====================================================================

[root@pupprdclt1 ~]# yum list squid
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos-hn.viettelidc.com.vn
 * extras: mirrors.vinahost.vn
 * updates: mirrors.viethosting.com
Available Packages
squid.x86_64                                                        7:3.1.23-24.el6                                                         base
[root@pupprdclt1




===================================================================
Go to the Puppetmaster node and create squid module using facter specification
===================================================================

[root@puppetmaster ~]# mkdir /etc/puppetlabs/code/environments/production/modules/squid

[root@puppetmaster ~]# cd /etc/puppetlabs/code/environments/production/modules/squid

[root@puppetmaster squid]#mkdir manifest

root@puppetmaster squid]# ls -l
total 12
drwxr-xr-x. 2 root root 4096 Oct 15 06:13 manifests


[root@puppetmaster squid]# cd manifests

[root@puppetmaster manifests]#



[root@puppetmaster manifests]#vi install.pp
class squid::install{
        if $osfamily == 'RedHat'{  <--------using RedHat facter output of osfamily
                        package{'squid':
                        ensure => installed,
                        }
        }
        elsif $osfamily == 'Debian'{
                package{'httpd':
                ensure => installed,
                        }
                }
}


[root@puppetmaster manifests]# vi init.pp
class squid{
        include squid::install             <------------- calling squid class
}

:x!

[root@puppetmaster manifests]#

[root@puppetmaster squid]#


[root@puppetmaster manifests]# ls -l *.pp
-rw-r--r--. 1 root root  39 Oct 15 06:34 init.pp
-rw-r--r--. 1 root root 187 Oct 15 06:26 install.pp
[root@puppetmaster manifests]#

-----------------------------------
Now go on client and call manifest
-----------------------------------
[root@pupprdclt1 ~]# puppet agent -tv
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for pupprdclt1.linuxchamps.com
Info: Applying configuration version '1508074488'
Notice: Hello World
Notice: /Stage[main]/Main/Notify[Hello World]/message: defined 'message' as 'Hello World'
Notice: /Stage[main]/Squid::Install/Package[squid]/ensure: created <-------- see installing Squid on
Notice: Applied catalog in 112.75 seconds
===================================================================
 Now check squid is installed or not on puppet client
===================================================================
[root@pupprdclt1 ~]# yum list squid
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos-hn.viettelidc.com.vn
 * extras: mirrors.vinahost.vn
 * updates: mirrors.viethosting.com
Installed Packages
squid.x86_64                                                        7:3.1.23-24.el6                                                 @base
[root@pupprdclt1 ~]#

No comments:

Post a Comment

kubernetes Pod Scheduling

 ===================   Deployment ================= 1.) Deployment without any nodeName or nodeSelector, pod will spread among all of the av...