Sunday, October 7, 2018

Practical hands on Puppet

=========== Puppet practice on Centos ===========
[root@puppetmaster modules]$  cd /etc/puppetlabs/code/environments/production/manifests/
[root@puppetmaster manifests]$  ls
[root@puppetmaster manifests]$  vi hello.pp
[root@puppetmaster manifests]$  cat hello.pp
notify {'Hello World':}
[root@puppetmaster manifests]$
================================================================================================
** If want to apply above on puppet server then use following command on puppet server

[root@puppetmaster manifests]$  puppet apply hello.pp
Notice: Compiled catalog for puppetmaster.localdomain in environment production in 0.02 seconds
Notice: Hello World
Notice: /Stage[main]/Main/Notify[Hello World]/message: defined 'message' as 'Hello World'
Notice: Applied catalog in 0.01 seconds

** If want to apply on puppet client to client then use following command on puppet server

[root@webprd1 ~]$  puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Caching catalog for webprd1.localdomain
Info: Applying configuration version '1538057264'
Notice: Hello World
Notice: /Stage[main]/Main/Notify[Hello World]/message: defined 'message' as 'Hello World'
Notice: Applied catalog in 0.03 seconds
[root@webprd1 ~]$

********* now we are using file resource type *********

[root@puppetmaster manifests]$  vi demo.pp
[root@puppetmaster manifests]$  cat demo.pp
file {'/tmp/demo.txt':
        ensure => present,
        content => 'Hello linuxchamps users',
        }


[root@webprd1 ~]$  puppet agent -t --noop    <----------------if you want to check what are new changes going to apply on client use noop this is dry run
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Applying configuration version '1538057956'
Notice: /Stage[main]/Main/File[/tmp/demo.txt]/ensure: current_value 'absent', should be 'present' (noop)    <------ its saying /tmp/demo.txt is absent should be present
Notice: /Stage[main]/Main/Notify[Hello World]/message: current_value 'absent', should be 'Hello World' (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 2 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 event
Notice: Applied catalog in 0.02 seconds
[root@webprd1 ~]$

[root@webprd1 ~]$  ll /tmp/demo.txt
ls: cannot access /tmp/demo.txt: No such file or directory  <------- Currenlty file is not present

[root@webprd1 ~]$  puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Caching catalog for webprd1.localdomain
Info: Applying configuration version '1538058210'
Notice: /Stage[main]/Main/File[/tmp/demo.txt]/ensure: defined content as '{md5}18a8acba178a037b8f1895c04eaf7387' <--- file is created
Notice: Hello World
Notice: /Stage[main]/Main/Notify[Hello World]/message: defined 'message' as 'Hello World'
Notice: Applied catalog in 0.11 seconds
[root@webprd1 ~]$
[root@webprd1 ~]$  cat /tmp/demo.txt   <------------ file is present at client side
Hello linuxchamps users                            

========== Now lets try to change file permissons ========

[root@puppetmaster manifests]$  cat demo.pp
file {'/tmp/demo.txt':
        ensure => present,
        content => 'Hello linuxchamps users',
        mode    => '774'
        }

[root@webprd1 ~]$  ll /tmp/demo.txt <-------- current permissons for /tmp/demo.txt
-rw-r--r--. 1 root root 23 Sep 27 19:53 /tmp/demo.txt

       
[root@webprd1 ~]$  puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Caching catalog for webprd1.localdomain
Info: Applying configuration version '1538058581'
Notice: /Stage[main]/Main/File[/tmp/demo.txt]/mode: mode changed '0644' to '0774'  <------- File permissons has been changed from 644 to 774
Notice: Hello World
Notice: /Stage[main]/Main/Notify[Hello World]/message: defined 'message' as 'Hello World'
Notice: Applied catalog in 0.02 seconds
[root@webprd1 ~]$

[root@webprd1 ~]$  ll /tmp/demo.txt
-rwxrwxr--. 1 root root 23 Sep 27 19:53 /tmp/demo.txt
[root@webprd1 ~]$

======== Lets see user creation via puppet =======

[root@puppetmaster manifests]$  cat user.pp 
user { 'anuj':
       ensure           => 'present',
       gid              => '501',
       home             => '/home/anuj',
       password         => '!!',
       password_max_age => '99999',
       password_min_age => '0',
       shell            => '/bin/bash',
       uid              => '501',
     }
group { 'appuser':
                gid  =>  '501',
  }

file { "/home/anuj":
    ensure            =>  directory,
    owner             =>  anuj,
    group             =>  appuser,
    mode              =>  '0750'
}


   
[root@webprd1 ~]$  grep -i anuj /etc/passwd <-------- on Puppet agent user anuj is not present
[root@webprd1 ~]$

[root@webprd1 home]$  grep -i appuser /etc/group


[root@webprd1 home]$  puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Caching catalog for webprd1.localdomain
Info: Applying configuration version '1538064313'
Notice: Hello World
Notice: /Stage[main]/Main/Notify[Hello World]/message: defined 'message' as 'Hello World'
Notice: /Stage[main]/Main/Group[appuser]/ensure: created    <--------------- group appuser created
Notice: /Stage[main]/Main/User[anuj]/ensure: created        <--------------- user anuj created
Notice: /Stage[main]/Main/File[/home/anuj]/ensure: created    <--------------- home directory created for user anuj
Notice: Applied catalog in 0.19 seconds
[root@webprd1 home]$


[root@webprd1 home]$  grep -i anuj /etc/passwd
anuj:x:501:501::/home/anuj:/bin/bash
[root@webprd1 home]$
[root@webprd1 home]$  grep -i appuser /etc/group
appuser:x:501:
[root@webprd1 home]$  su - anuj
-bash-4.2$

================= lets try to install package via puppet on client ==============

[root@puppetmaster manifests]$  vi /etc/puppetlabs/code/environments/production/manifests/package.pp
package {'httpd':
        ensure  => present,
        name    => 'httpd'
        }
        service {'httpd':
                ensure  => running,
                enable    => true,
        }

*** have a look httpd package is not present on client at this mommnet  <==========

[root@webprd1 puppet]$  yum list httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.nbrc.ac.in
 * epel: mirror1.ku.ac.th
 * extras: mirrors.fibergrid.in
 * updates: mirrors.fibergrid.in
Available Packages
httpd.x86_64                                                2.4.6-80.el7.centos.1                                                updates


[root@webprd1 puppet]$  puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Caching catalog for webprd1.localdomain
Info: Applying configuration version '1538096426'
Notice: Hello World
Notice: /Stage[main]/Main/Notify[Hello World]/message: defined 'message' as 'Hello World'
Notice: /Stage[main]/Main/Package[httpd]/ensure: created                        <======================== httpd package has been installed
Notice: /Stage[main]/Main/Service[httpd]/ensure: ensure changed 'stopped' to 'running' <================= httpd service has been started
Notice: /Stage[main]/Main/Service[httpd]/enable: enable changed 'false' to 'true'        <================ httpd service has been added at startup
Info: /Stage[main]/Main/Service[httpd]: Unscheduling refresh on Service[httpd]
Notice: Applied catalog in 84.98 seconds


[root@webprd1 ~]$  ps -ef | grep -i yum
root     15177 15089 10 06:30 ?        00:00:09 /usr/bin/python /usr/bin/yum -d 0 -e 0 -y install httpd  <=========== backend it call yum to install httpd
root     15345 15211  0 06:31 pts/3    00:00:00 grep --color=auto -i yum
[root@webprd1 ~]$
[root@webprd1 ~]$
[root@webprd1 ~]$  ps -ef | grep -i yum
root     15391 15211  0 06:31 pts/3    00:00:00 grep --color=auto -i yum
       

Puppet installatoin via yum

==========  =============


[root@puppetmaster ~]#  rpm -Uvh https://yum.puppetlabs.com/puppet5/puppet5-release-el-7.noarch.rpm
Retrieving https://yum.puppetlabs.com/puppet5/puppet5-release-el-7.noarch.rpm
warning: /var/tmp/rpm-tmp.gBV2Pb: Header V4 RSA/SHA256 Signature, key ID ef8d349f: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:puppet5-release-5.0.0-4.el7      ################################# [100%]
[root@puppetmaster ~]# yum install -y puppetserver
Loaded plugins: fastestmirror, langpacks
base                                                                                                             | 3.6 kB  00:00:00
epel/x86_64/metalink                                                                                             | 7.9 kB  00:00:00
extras                                                                                                           | 3.4 kB  00:00:00
puppet5                                                                                                          | 2.5 kB  00:00:00
updates                                                                                                          | 3.4 kB  00:00:00
puppet5/x86_64/primary_db                                                                                        | 128 kB  00:00:00
Loading mirror speeds from cached hostfile
 * base: mirror.nbrc.ac.in
 * epel: mirror1.ku.ac.th
 * extras: mirrors.fibergrid.in
 * updates: mirrors.fibergrid.in
Resolving Dependencies
--> Running transaction check
---> Package puppetserver.noarch 0:5.3.5-1.el7 will be installed
--> Processing Dependency: puppet-agent >= 4.99.0 for package: puppetserver-5.3.5-1.el7.noarch
--> Running transaction check
---> Package puppet-agent.x86_64 0:5.5.6-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================
 Package                            Arch                         Version                            Repository                     Size
========================================================================================================================================
Installing:
 puppetserver                       noarch                       5.3.5-1.el7                        puppet5                        67 M
Installing for dependencies:
 puppet-agent                       x86_64                       5.5.6-1.el7                        puppet5                        20 M

Transaction Summary
========================================================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 86 M
Installed size: 86 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/puppet5/packages/puppet-agent-5.5.6-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID ef8d349f: NOKEY
Public key for puppet-agent-5.5.6-1.el7.x86_64.rpm is not installed
(1/2): puppet-agent-5.5.6-1.el7.x86_64.rpm                                                                       |  20 MB  00:00:10
(2/2): puppetserver-5.3.5-1.el7.noarch.rpm                                                                       |  67 MB  00:00:26
----------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                   3.3 MB/s |  86 MB  00:00:26
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppet5-release
Importing GPG key 0xEF8D349F:
 Userid     : "Puppet, Inc. Release Key (Puppet, Inc. Release Key) <release@puppet.com>"
 Fingerprint: 6f6b 1550 9cf8 e59e 6e46 9f32 7f43 8280 ef8d 349f
 Package    : puppet5-release-5.0.0-4.el7.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-puppet5-release
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 3 pre-existing rpmdb problem(s), 'yum check' output follows:
ipa-client-4.4.0-14.el7.centos.6.x86_64 has installed conflicts freeipa-client: ipa-client-4.4.0-14.el7.centos.6.x86_64
ipa-client-common-4.4.0-14.el7.centos.6.noarch has installed conflicts freeipa-client-common: ipa-client-common-4.4.0-14.el7.centos.6.noarch
ipa-common-4.4.0-14.el7.centos.6.noarch has installed conflicts freeipa-common: ipa-common-4.4.0-14.el7.centos.6.noarch
  Installing : puppet-agent-5.5.6-1.el7.x86_64                                                                                      1/2
  Installing : puppetserver-5.3.5-1.el7.noarch                                                                                      2/2
usermod: no changes
  Verifying  : puppet-agent-5.5.6-1.el7.x86_64                                                                                      1/2
  Verifying  : puppetserver-5.3.5-1.el7.noarch                                                                                      2/2

Installed:
  puppetserver.noarch 0:5.3.5-1.el7

Dependency Installed:
  puppet-agent.x86_64 0:5.5.6-1.el7

Complete!
[root@puppetmaster ~]#  yum -y install ntpdate
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.nbrc.ac.in
 * epel: mirror1.ku.ac.th
 * extras: mirrors.fibergrid.in
 * updates: mirrors.fibergrid.in
Resolving Dependencies
--> Running transaction check
---> Package ntpdate.x86_64 0:4.2.6p5-25.el7.centos.1 will be updated
--> Processing Dependency: ntpdate = 4.2.6p5-25.el7.centos.1 for package: ntp-4.2.6p5-25.el7.centos.1.x86_64
---> Package ntpdate.x86_64 0:4.2.6p5-28.el7.centos will be an update
--> Processing Dependency: libcrypto.so.10(OPENSSL_1.0.2)(64bit) for package: ntpdate-4.2.6p5-28.el7.centos.x86_64
--> Running transaction check
---> Package ntp.x86_64 0:4.2.6p5-25.el7.centos.1 will be updated
---> Package ntp.x86_64 0:4.2.6p5-28.el7.centos will be an update
---> Package openssl-libs.x86_64 1:1.0.1e-60.el7_3.1 will be updated
--> Processing Dependency: openssl-libs(x86-64) = 1:1.0.1e-60.el7_3.1 for package: 1:openssl-1.0.1e-60.el7_3.1.x86_64
---> Package openssl-libs.x86_64 1:1.0.2k-12.el7 will be an update
--> Running transaction check
---> Package openssl.x86_64 1:1.0.1e-60.el7_3.1 will be updated
---> Package openssl.x86_64 1:1.0.2k-12.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================
 Package                          Arch                       Version                                     Repository                Size
========================================================================================================================================
Updating:
 ntpdate                          x86_64                     4.2.6p5-28.el7.centos                       base                      86 k
Updating for dependencies:
 ntp                              x86_64                     4.2.6p5-28.el7.centos                       base                     549 k
 openssl                          x86_64                     1:1.0.2k-12.el7                             base                     492 k
 openssl-libs                     x86_64                     1:1.0.2k-12.el7                             base                     1.2 M

Transaction Summary
========================================================================================================================================
Upgrade  1 Package (+3 Dependent packages)

Total download size: 2.3 M
Downloading packages:
No Presto metadata available for base
(1/4): ntpdate-4.2.6p5-28.el7.centos.x86_64.rpm                                                                  |  86 kB  00:00:01
(2/4): ntp-4.2.6p5-28.el7.centos.x86_64.rpm                                                                      | 549 kB  00:00:02
(3/4): openssl-libs-1.0.2k-12.el7.x86_64.rpm                                                                     | 1.2 MB  00:00:04
(4/4): openssl-1.0.2k-12.el7.x86_64.rpm                                                                          | 492 kB  00:00:06
----------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                   347 kB/s | 2.3 MB  00:00:06
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : 1:openssl-libs-1.0.2k-12.el7.x86_64                                                                                  1/8
  Updating   : ntpdate-4.2.6p5-28.el7.centos.x86_64                                                                                 2/8
  Updating   : ntp-4.2.6p5-28.el7.centos.x86_64                                                                                     3/8
  Updating   : 1:openssl-1.0.2k-12.el7.x86_64                                                                                       4/8
  Cleanup    : ntp-4.2.6p5-25.el7.centos.1.x86_64                                                                                   5/8
  Cleanup    : ntpdate-4.2.6p5-25.el7.centos.1.x86_64                                                                               6/8
  Cleanup    : 1:openssl-1.0.1e-60.el7_3.1.x86_64                                                                                   7/8
  Cleanup    : 1:openssl-libs-1.0.1e-60.el7_3.1.x86_64                                                                              8/8
  Verifying  : ntp-4.2.6p5-28.el7.centos.x86_64                                                                                     1/8
  Verifying  : ntpdate-4.2.6p5-28.el7.centos.x86_64                                                                                 2/8
  Verifying  : 1:openssl-1.0.2k-12.el7.x86_64                                                                                       3/8
  Verifying  : 1:openssl-libs-1.0.2k-12.el7.x86_64                                                                                  4/8
  Verifying  : 1:openssl-1.0.1e-60.el7_3.1.x86_64                                                                                   5/8
  Verifying  : ntpdate-4.2.6p5-25.el7.centos.1.x86_64                                                                               6/8
  Verifying  : ntp-4.2.6p5-25.el7.centos.1.x86_64                                                                                   7/8
  Verifying  : 1:openssl-libs-1.0.1e-60.el7_3.1.x86_64                                                                              8/8

Updated:
  ntpdate.x86_64 0:4.2.6p5-28.el7.centos

Dependency Updated:
  ntp.x86_64 0:4.2.6p5-28.el7.centos            openssl.x86_64 1:1.0.2k-12.el7            openssl-libs.x86_64 1:1.0.2k-12.el7

Complete!
[root@puppetmaster ~]#  ntpdate 0.centos.pool.ntp.org
26 Sep 11:34:25 ntpdate[7072]: adjust time server 80.92.126.65 offset -0.001449 sec
[root@puppetmaster ~]# ntpdate
26 Sep 11:34:29 ntpdate[7073]: no servers can be used, exiting
[root@puppetmaster ~]# ntp
ntpd        ntpdate     ntpdc       ntp-keygen  ntpq        ntpstat     ntptime
[root@puppetmaster ~]# ntpstat
Unable to talk to NTP daemon. Is it running?
[root@puppetmaster ~]# systemctl start ntpd
[root@puppetmaster ~]# ntpstat
unsynchronised
  time server re-starting
   polling server every 8 s
[root@puppetmaster ~]# ntpdate
26 Sep 11:35:05 ntpdate[7085]: no servers can be used, exiting
[root@puppetmaster ~]# ntptime
ntp_gettime() returns code 0 (OK)
  time df5625ba.0e35c5b0  Wed, Sep 26 2018 11:35:22.055, (.055508370),
  maximum error 1239605 us, estimated error 21119 us, TAI offset 0
ntp_adjtime() returns code 0 (OK)
  modes 0x0 (),
  offset -55889.694 us, frequency -0.399 ppm, interval 1 s,
  maximum error 1239605 us, estimated error 21119 us,
  status 0x2001 (PLL,NANO),
  time constant 6, precision 0.001 us, tolerance 500 ppm,
[root@puppetmaster ~]# date
Wed Sep 26 11:35:29 EDT 2018
[root@puppetmaster ~]# timedatectl set-timezone Asia/Kolkata
[root@puppetmaster ~]# ntptime
ntp_gettime() returns code 0 (OK)
  time df5625da.cca5ac80  Wed, Sep 26 2018 21:05:54.799, (.799403733),
  maximum error 1255605 us, estimated error 21119 us, TAI offset 0
ntp_adjtime() returns code 0 (OK)
  modes 0x0 (),
  offset -49310.410 us, frequency -0.399 ppm, interval 1 s,
  maximum error 1255605 us, estimated error 21119 us,
  status 0x2001 (PLL,NANO),
  time constant 6, precision 0.001 us, tolerance 500 ppm,
[root@puppetmaster ~]#
[root@puppetmaster ~]# date
Wed Sep 26 21:05:58 IST 2018
[root@puppetmaster ~]#  export PS1="\e[1;31m[\u@\h \W]\$ \e[m "
[root@puppetmaster ~]$
[root@puppetmaster ~]$
[root@puppetmaster ~]$   systemctl status puppetserver
● puppetserver.service - puppetserver Service
   Loaded: loaded (/usr/lib/systemd/system/puppetserver.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
[root@puppetmaster ~]$  systemctl start puppetserver
[root@puppetmaster ~]$  systemctl start puppetserver^C
[root@puppetmaster ~]$  systemctl enable puppetserver
Created symlink from /etc/systemd/system/multi-user.target.wants/puppetserver.service to /usr/lib/systemd/system/puppetserver.service.
[root@puppetmaster ~]$
[root@puppetmaster ~]$

================= setting up puppet client ==============

[root@webdev1 network-scripts]#  yum -y install ntpdate
Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
base                                                                                                             | 3.6 kB  00:00:00
epel/x86_64/metalink                                                                                             | 7.9 kB  00:00:00
epel                                                                                                             | 3.2 kB  00:00:00
extras                                                                                                           | 3.4 kB  00:00:00
updates                                                                                                          | 3.4 kB  00:00:00
(1/5): epel/x86_64/group_gz                                                                                      |  88 kB  00:00:00
(2/5): extras/7/x86_64/primary_db                                                                                | 187 kB  00:00:00
(3/5): updates/7/x86_64/primary_db                                                                               | 5.2 MB  00:00:01
(4/5): epel/x86_64/updateinfo                                                                                    | 943 kB  00:00:02
(5/5): epel/x86_64/primary                                                                                       | 3.6 MB  00:00:07
Loading mirror speeds from cached hostfile
 * base: centos.mirror.net.in
 * epel: mirror1.ku.ac.th
 * extras: centos.mirror.net.in
 * updates: centos.mirror.net.in
epel                                                                                                                        12687/12687
Resolving Dependencies
--> Running transaction check
---> Package ntpdate.x86_64 0:4.2.6p5-25.el7.centos.1 will be updated
--> Processing Dependency: ntpdate = 4.2.6p5-25.el7.centos.1 for package: ntp-4.2.6p5-25.el7.centos.1.x86_64
---> Package ntpdate.x86_64 0:4.2.6p5-28.el7.centos will be an update
--> Processing Dependency: libcrypto.so.10(OPENSSL_1.0.2)(64bit) for package: ntpdate-4.2.6p5-28.el7.centos.x86_64
--> Running transaction check
---> Package ntp.x86_64 0:4.2.6p5-25.el7.centos.1 will be updated
---> Package ntp.x86_64 0:4.2.6p5-28.el7.centos will be an update
---> Package openssl-libs.x86_64 1:1.0.1e-60.el7_3.1 will be updated
--> Processing Dependency: openssl-libs(x86-64) = 1:1.0.1e-60.el7_3.1 for package: 1:openssl-1.0.1e-60.el7_3.1.x86_64
---> Package openssl-libs.x86_64 1:1.0.2k-12.el7 will be an update
--> Running transaction check
---> Package openssl.x86_64 1:1.0.1e-60.el7_3.1 will be updated
---> Package openssl.x86_64 1:1.0.2k-12.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================
 Package                          Arch                       Version                                     Repository                Size
========================================================================================================================================
Updating:
 ntpdate                          x86_64                     4.2.6p5-28.el7.centos                       base                      86 k
Updating for dependencies:
 ntp                              x86_64                     4.2.6p5-28.el7.centos                       base                     549 k
 openssl                          x86_64                     1:1.0.2k-12.el7                             base                     492 k
 openssl-libs                     x86_64                     1:1.0.2k-12.el7                             base                     1.2 M

Transaction Summary
========================================================================================================================================
Upgrade  1 Package (+3 Dependent packages)

Total size: 2.3 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : 1:openssl-libs-1.0.2k-12.el7.x86_64                                                                                  1/8
  Updating   : ntpdate-4.2.6p5-28.el7.centos.x86_64                                                                                 2/8
  Updating   : ntp-4.2.6p5-28.el7.centos.x86_64                                                                                     3/8
  Updating   : 1:openssl-1.0.2k-12.el7.x86_64                                                                                       4/8
  Cleanup    : ntp-4.2.6p5-25.el7.centos.1.x86_64                                                                                   5/8
  Cleanup    : ntpdate-4.2.6p5-25.el7.centos.1.x86_64                                                                               6/8
  Cleanup    : 1:openssl-1.0.1e-60.el7_3.1.x86_64                                                                                   7/8
  Cleanup    : 1:openssl-libs-1.0.1e-60.el7_3.1.x86_64                                                                              8/8
  Verifying  : ntp-4.2.6p5-28.el7.centos.x86_64                                                                                     1/8
  Verifying  : ntpdate-4.2.6p5-28.el7.centos.x86_64                                                                                 2/8
  Verifying  : 1:openssl-1.0.2k-12.el7.x86_64                                                                                       3/8
  Verifying  : 1:openssl-libs-1.0.2k-12.el7.x86_64                                                                                  4/8
  Verifying  : 1:openssl-1.0.1e-60.el7_3.1.x86_64                                                                                   5/8
  Verifying  : ntpdate-4.2.6p5-25.el7.centos.1.x86_64                                                                               6/8
  Verifying  : ntp-4.2.6p5-25.el7.centos.1.x86_64                                                                                   7/8
  Verifying  : 1:openssl-libs-1.0.1e-60.el7_3.1.x86_64                                                                              8/8

Updated:
  ntpdate.x86_64 0:4.2.6p5-28.el7.centos

Dependency Updated:
  ntp.x86_64 0:4.2.6p5-28.el7.centos            openssl.x86_64 1:1.0.2k-12.el7            openssl-libs.x86_64 1:1.0.2k-12.el7

Complete!
[root@webdev1 network-scripts]# ntpdate 0.centos.pool.ntp.org
26 Sep 11:45:39 ntpdate[6549]: adjust time server 167.99.64.239 offset 0.011970 sec
[root@webdev1 network-scripts]# timedatectl set-timezone Asia/Kolkata
[root@webdev1 network-scripts]# date
Wed Sep 26 21:16:01 IST 2018
[root@webdev1 network-scripts]# systemctl start ntpd
[root@webdev1 network-scripts]#  yum -y install ntpdate^C
[root@webdev1 network-scripts]#  rpm -Uvh https://yum.puppetlabs.com/puppet5/puppet5-release-el-7.noarch.rpm
Retrieving https://yum.puppetlabs.com/puppet5/puppet5-release-el-7.noarch.rpm
warning: /var/tmp/rpm-tmp.kWtwPV: Header V4 RSA/SHA256 Signature, key ID ef8d349f: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:puppet5-release-5.0.0-4.el7      ################################# [100%]
[root@webdev1 network-scripts]# yum install puppet
Loaded plugins: fastestmirror, langpacks
puppet5                                                                                                          | 2.5 kB  00:00:00
puppet5/x86_64/primary_db                                                                                        | 128 kB  00:00:00
Loading mirror speeds from cached hostfile
 * base: centos.mirror.net.in
 * epel: mirrors.nipa.cloud
 * extras: centos.mirror.net.in
 * updates: centos.mirror.net.in
Package puppet is obsoleted by puppet-agent, trying to install puppet-agent-5.5.6-1.el7.x86_64 instead
Resolving Dependencies
--> Running transaction check
---> Package puppet-agent.x86_64 0:5.5.6-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================
 Package                            Arch                         Version                            Repository                     Size
========================================================================================================================================
Installing:
 puppet-agent                       x86_64                       5.5.6-1.el7                        puppet5                        20 M

Transaction Summary
========================================================================================================================================
Install  1 Package

Total download size: 20 M
Installed size: 20 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/puppet5/packages/puppet-agent-5.5.6-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID ef8d349f: NOKEY
Public key for puppet-agent-5.5.6-1.el7.x86_64.rpm is not installed
puppet-agent-5.5.6-1.el7.x86_64.rpm                                                                              |  20 MB  00:00:14
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppet5-release
Importing GPG key 0xEF8D349F:
 Userid     : "Puppet, Inc. Release Key (Puppet, Inc. Release Key) <release@puppet.com>"
 Fingerprint: 6f6b 1550 9cf8 e59e 6e46 9f32 7f43 8280 ef8d 349f
 Package    : puppet5-release-5.0.0-4.el7.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-puppet5-release
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 3 pre-existing rpmdb problem(s), 'yum check' output follows:
ipa-client-4.4.0-14.el7.centos.6.x86_64 has installed conflicts freeipa-client: ipa-client-4.4.0-14.el7.centos.6.x86_64
ipa-client-common-4.4.0-14.el7.centos.6.noarch has installed conflicts freeipa-client-common: ipa-client-common-4.4.0-14.el7.centos.6.noarch
ipa-common-4.4.0-14.el7.centos.6.noarch has installed conflicts freeipa-common: ipa-common-4.4.0-14.el7.centos.6.noarch
  Installing : puppet-agent-5.5.6-1.el7.x86_64                                                                                      1/1
  Verifying  : puppet-agent-5.5.6-1.el7.x86_64                                                                                      1/1

Installed:
  puppet-agent.x86_64 0:5.5.6-1.el7

Complete!
[root@webdev1 network-scripts]#
 

Thursday, December 7, 2017

miscellaneous day to day admin task

1.) sort /etc/passwd on uid.

[anuj@oc5380700602 ~]$ sort -t: -k 3,4 -g /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

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 ~]#

Learning Puppet

[root@anujpupetmaster ~]# cd /tmp/puppet-enterprise-2015.3.3-el-6-x86_64
[root@anujpupetmaster puppet-enterprise-2015.3.3-el-6-x86_64]# ./puppet-enterprise-installer
========================================================================================================================================================================

Puppet Enterprise v2015.3.3 installer

Puppet Enterprise documentation can be found at http://docs.puppetlabs.com/pe/2015.3/

------------------------------------------------------------------------------------------------------------------------------------------------------------------------

STEP 1: GUIDED INSTALLATION

Before you begin, choose an installation method. We've provided a few paths to choose from.

- Perform a guided installation using the web-based interface. Think of this as an installation interview in which we ask you exactly how you want to install PE. In
order to use the web-based installer, you must be able to access this machine on port 3000 and provide the SSH credentials of a user with root access. This method
will login to servers on your behalf, install Puppet Enterprise and get you up and running fairly quickly.

- Use the web-based interface to create an answer file so that you can log in to the servers yourself and perform the installation locally. If you choose not to use
the web-based interface, you can write your own answer file, or use the answer file(s) provided in the PE installation tarball. Refer to Answer File Installation
(http://docs.puppetlabs.com/pe/2015.3/install_automated.html), which provides an overview on installing PE with an answer file.

?? Install packages and perform a guided install? [Y/n] Y

Installing setup packages.

Please go to https://anujpupetmaster:3000 in your browser to continue installation. Be sure to use https:// and that port 3000 is reachable through the firewall.

Your infrastructure has finished installing.
Thank you for installing Puppet Enterprise!
[root@anujpupetmaster puppet-enterprise-2015.3.3-el-6-x86_64]#

Monday, April 9, 2012

Top 10 Open Source Bug Tracking System

Logrotate in Linux server

Logs are important and usefull in security and administration. If a log grows too much, you compress it , back it up for some months or years and create a new log file. All this is done in a much better way by Logrotate. Logrotate enables you to compress the old logfile, and store it for as long as you want, to run every day, montly, or when you want, and if a file expires, it can send it to you by email or delete it, after for example, 2 years. Old logs can be stored in an alternative directory.

You set up logs configuring /etc/logrotate.conf or adding a new file in /etc/logrotate.d/
For example, a logrotate file for apache looks like this:
File: /etc/logrotate.d/httpd
-------8<------- /usr/local/apache/logs/*log { missingok notifempty sharedscripts postrotate /bin/kill -USR1 `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
endscript
}

Complete list of  recommended VS Code extensions  for writing and managing  AWS Terraform scripts , including syntax checking, variable supp...