Wednesday, May 1, 2019

Ansible how to

How to install ansible:
==============
[root@ansimaster ~]# yum install ansible
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: repos.del.extreme-ix.org
 * epel: repos.del.extreme-ix.org
 * extras: repos.del.extreme-ix.org
 * updates: repos.del.extreme-ix.org
Resolving Dependencies
--> Running transaction check
---> Package ansible.noarch 0:2.7.10-1.el7 will be installed
--> Processing Dependency: PyYAML for package: ansible-2.7.10-1.el7.noarch
--> Processing Dependency: python-crypto for package: ansible-2.7.10-1.el7.noarch
--> Processing Dependency: python-httplib2 for package: ansible-2.7.10-1.el7.noarch
--> Processing Dependency: python-jinja2 for package: ansible-2.7.10-1.el7.noarch
--> Processing Dependency: python-keyczar for package: ansible-2.7.10-1.el7.noarch
--> Processing Dependency: python-paramiko for package: ansible-2.7.10-1.el7.noarch
--> Processing Dependency: python2-jmespath for package: ansible-2.7.10-1.el7.noarch
--> Processing Dependency: sshpass for package: ansible-2.7.10-1.el7.noarch
--> Running transaction check
---> Package PyYAML.x86_64 0:3.10-11.el7 will be installed
--> Processing Dependency: libyaml-0.so.2()(64bit) for package: PyYAML-3.10-11.el7.x86_64
---> Package python-httplib2.noarch 0:0.9.2-1.el7 will be installed
---> Package python-jinja2.noarch 0:2.7.2-2.el7 will be installed
--> Processing Dependency: python-babel >= 0.8 for package: python-jinja2-2.7.2-2.el7.noarch
--> Processing Dependency: python-markupsafe for package: python-jinja2-2.7.2-2.el7.noarch
---> Package python-keyczar.noarch 0:0.71c-2.el7 will be installed
---> Package python-paramiko.noarch 0:2.1.1-9.el7 will be installed
---> Package python2-crypto.x86_64 0:2.6.1-16.el7 will be installed
--> Processing Dependency: libtomcrypt.so.0()(64bit) for package: python2-crypto-2.6.1-16.el7.x86_64
---> Package python2-jmespath.noarch 0:0.9.0-3.el7 will be installed
---> Package sshpass.x86_64 0:1.06-2.el7 will be installed
--> Running transaction check
---> Package libtomcrypt.x86_64 0:1.17-26.el7 will be installed
--> Processing Dependency: libtommath >= 0.42.0 for package: libtomcrypt-1.17-26.el7.x86_64
--> Processing Dependency: libtommath.so.0()(64bit) for package: libtomcrypt-1.17-26.el7.x86_64
---> Package libyaml.x86_64 0:0.1.4-11.el7_0 will be installed
---> Package python-babel.noarch 0:0.9.6-8.el7 will be installed
---> Package python-markupsafe.x86_64 0:0.11-10.el7 will be installed
--> Running transaction check
---> Package libtommath.x86_64 0:0.42.0-6.el7 will be installed
--> Finished Dependency Resolution
/var/cache/yum/x86_64/7/base/gen/comps.xml: no element found: line 1, column 0
/var/cache/yum/x86_64/7/epel/gen/comps.xml: no element found: line 1, column 0

Dependencies Resolved

=========================================================================================================================================
 Package                               Arch                       Version                              Repository                   Size
=========================================================================================================================================
Installing:
 ansible                               noarch                     2.7.10-1.el7                         epel                         11 M
Installing for dependencies:
 PyYAML                                x86_64                     3.10-11.el7                          base                        153 k
 libtomcrypt                           x86_64                     1.17-26.el7                          extras                      224 k
 libtommath                            x86_64                     0.42.0-6.el7                         extras                       36 k
 libyaml                               x86_64                     0.1.4-11.el7_0                       base                         55 k
 python-babel                          noarch                     0.9.6-8.el7                          base                        1.4 M
 python-httplib2                       noarch                     0.9.2-1.el7                          extras                      115 k
 python-jinja2                         noarch                     2.7.2-2.el7                          base                        515 k
 python-keyczar                        noarch                     0.71c-2.el7                          epel                        218 k
 python-markupsafe                     x86_64                     0.11-10.el7                          base                         25 k
 python-paramiko                       noarch                     2.1.1-9.el7                          updates                     269 k
 python2-crypto                        x86_64                     2.6.1-16.el7                         epel                        477 k
 python2-jmespath                      noarch                     0.9.0-3.el7                          extras                       39 k
 sshpass                               x86_64                     1.06-2.el7                           extras                       21 k

Transaction Summary
=========================================================================================================================================
Install  1 Package (+13 Dependent packages)

Total download size: 15 M
Installed size: 74 M
Is this ok [y/d/N]: y
Downloading packages:
(1/14): libtommath-0.42.0-6.el7.x86_64.rpm                                                                        |  36 kB  00:00:00
(2/14): libyaml-0.1.4-11.el7_0.x86_64.rpm                                                                         |  55 kB  00:00:00
(3/14): libtomcrypt-1.17-26.el7.x86_64.rpm                                                                        | 224 kB  00:00:00
(4/14): PyYAML-3.10-11.el7.x86_64.rpm                                                                             | 153 kB  00:00:00
(5/14): python-jinja2-2.7.2-2.el7.noarch.rpm                                                                      | 515 kB  00:00:00
(6/14): python-httplib2-0.9.2-1.el7.noarch.rpm                                                                    | 115 kB  00:00:00
(7/14): python-babel-0.9.6-8.el7.noarch.rpm                                                                       | 1.4 MB  00:00:00
(8/14): ansible-2.7.10-1.el7.noarch.rpm                                                                           |  11 MB  00:00:03
(9/14): python-keyczar-0.71c-2.el7.noarch.rpm                                                                     | 218 kB  00:00:00
(10/14): python2-crypto-2.6.1-16.el7.x86_64.rpm                                                                   | 477 kB  00:00:00
(11/14): sshpass-1.06-2.el7.x86_64.rpm                                                                            |  21 kB  00:00:00
(12/14): python-markupsafe-0.11-10.el7.x86_64.rpm                                                                 |  25 kB  00:00:00
(13/14): python2-jmespath-0.9.0-3.el7.noarch.rpm                                                                  |  39 kB  00:00:00
(14/14): python-paramiko-2.1.1-9.el7.noarch.rpm                                                                   | 269 kB  00:00:00
-----------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                    3.2 MB/s |  15 MB  00:00:04
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : python-httplib2-0.9.2-1.el7.noarch                                                                                   1/14
  Installing : sshpass-1.06-2.el7.x86_64                                                                                            2/14
  Installing : libtommath-0.42.0-6.el7.x86_64                                                                                       3/14
  Installing : libtomcrypt-1.17-26.el7.x86_64                                                                                       4/14
  Installing : python2-crypto-2.6.1-16.el7.x86_64                                                                                   5/14
  Installing : python-keyczar-0.71c-2.el7.noarch                                                                                    6/14
  Installing : python-babel-0.9.6-8.el7.noarch                                                                                      7/14
  Installing : python-markupsafe-0.11-10.el7.x86_64                                                                                 8/14
  Installing : python-jinja2-2.7.2-2.el7.noarch                                                                                     9/14
  Installing : python-paramiko-2.1.1-9.el7.noarch                                                                                  10/14
  Installing : python2-jmespath-0.9.0-3.el7.noarch                                                                                 11/14
  Installing : libyaml-0.1.4-11.el7_0.x86_64                                                                                       12/14
  Installing : PyYAML-3.10-11.el7.x86_64                                                                                           13/14
  Installing : ansible-2.7.10-1.el7.noarch                                                                                         14/14
  Verifying  : python-keyczar-0.71c-2.el7.noarch                                                                                    1/14
  Verifying  : libyaml-0.1.4-11.el7_0.x86_64                                                                                        2/14
  Verifying  : python-jinja2-2.7.2-2.el7.noarch                                                                                     3/14
  Verifying  : python2-jmespath-0.9.0-3.el7.noarch                                                                                  4/14
  Verifying  : python-paramiko-2.1.1-9.el7.noarch                                                                                   5/14
  Verifying  : python-markupsafe-0.11-10.el7.x86_64                                                                                 6/14
  Verifying  : python-babel-0.9.6-8.el7.noarch                                                                                      7/14
  Verifying  : python2-crypto-2.6.1-16.el7.x86_64                                                                                   8/14
  Verifying  : libtommath-0.42.0-6.el7.x86_64                                                                                       9/14
  Verifying  : sshpass-1.06-2.el7.x86_64                                                                                           10/14
  Verifying  : python-httplib2-0.9.2-1.el7.noarch                                                                                  11/14
  Verifying  : ansible-2.7.10-1.el7.noarch                                                                                         12/14
  Verifying  : PyYAML-3.10-11.el7.x86_64                                                                                           13/14
  Verifying  : libtomcrypt-1.17-26.el7.x86_64                                                                                      14/14

Installed:
  ansible.noarch 0:2.7.10-1.el7

Dependency Installed:
  PyYAML.x86_64 0:3.10-11.el7                 libtomcrypt.x86_64 0:1.17-26.el7            libtommath.x86_64 0:0.42.0-6.el7
  libyaml.x86_64 0:0.1.4-11.el7_0             python-babel.noarch 0:0.9.6-8.el7           python-httplib2.noarch 0:0.9.2-1.el7
  python-jinja2.noarch 0:2.7.2-2.el7          python-keyczar.noarch 0:0.71c-2.el7         python-markupsafe.x86_64 0:0.11-10.el7
  python-paramiko.noarch 0:2.1.1-9.el7        python2-crypto.x86_64 0:2.6.1-16.el7        python2-jmespath.noarch 0:0.9.0-3.el7
  sshpass.x86_64 0:1.06-2.el7

Complete!

2.) both master and client should ping from there hosts name

192.168.159.142 web1 <===== ansible client
192.168.159.141 ansimaster <===== ansible master

[root@ansimaster ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 ansimaster
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.159.142 web1
192.168.159.141 ansimaster
[root@ansimaster ~]#


[root@web1 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 web1
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.159.142 web1
192.168.159.141 ansimaster

3.) Now make them password less login

[root@ansimaster ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
5e:09:e1:2f:2f:78:63:c2:92:2e:23:9a:20:60:c5:0a root@ansimaster
The key's randomart image is:
+--[ RSA 2048]----+
|        .        |
|  .    . .       |
|E  o    o        |
|. o      o .     |
|.o      S +      |
|o    o o +       |
|o   o + * .      |
|+.o. . + o       |
|+. o.            |
+-----------------+
[root@ansimaster ~]# ssh-copy-id web1
The authenticity of host 'web1 (192.168.159.142)' can't be established.
ECDSA key fingerprint is f8:8e:8d:80:45:39:74:d5:96:70:8d:c3:16:7e:ee:e0.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@web1's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'web1'"
and check to make sure that only the key(s) you wanted were added.

[root@ansimaster ~]# ssh web1
Last login: Wed May  1 03:50:01 2019 from 192.168.159.1
[root@web1 ~]# exit
logout
Connection to web1 closed.

[root@web1 ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
e3:df:d3:20:fb:42:02:a0:46:f1:10:cf:46:8d:31:63 root@web1
The key's randomart image is:
+--[ RSA 2048]----+
|  +oE+           |
|  .Boo.          |
| . .=.           |
|  o.  .          |
| .     .S        |
|       ...o .    |
|        .o o o   |
|         .o.. .  |
|          .oo.   |
+-----------------+

[root@web1 ~]#
[root@web1 ~]# ssh-copy-id ansimaster
The authenticity of host 'ansimaster (192.168.159.141)' can't be established.
ECDSA key fingerprint is f8:8e:8d:80:45:39:74:d5:96:70:8d:c3:16:7e:ee:e0.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@ansimaster's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'ansimaster'"
and check to make sure that only the key(s) you wanted were added.

[root@web1 ~]# ssh ansimaster
Last login: Wed May  1 03:53:52 2019 from 192.168.159.1
[root@ansimaster ~]# exit
logout
Connection to ansimaster closed.
[root@web1 ~]#


================== Adding clients ============

1.)
[root@ansimaster ~]# tail -5 /etc/ansible/hosts
# leading 0s:

## db-[99:101]-node.example.com
[webservers]  <=====  group we created for web servers and you can give more then one server to it.
192.168.159.142   <============= this is the first client as web server


2.) Now check ansible server is able to connect with anisble webserver group

[root@ansimaster ~]# ansible -m ping webservers
192.168.159.142 | SUCCESS => {
    "changed": false,
    "ping": "pong"    <===== ping response as pong from client which means all good.
}
[root@ansimaster ~]#




3.) To list all available ansible module that we can use.

[root@ansimaster ~]# ansible-doc -l
a10_server                                           Manage A10 Networks AX/SoftAX/Thunder/vThunder devices' server object.
a10_server_axapi3                                    Manage A10 Networks AX/SoftAX/Thunder/vThunder devices
a10_service_group                                    Manage A10 Networks AX/SoftAX/Thunder/vThunder devices' service groups.
a10_virtual_server                                   Manage A10 Networks AX/SoftAX/Thunder/vThunder devices' virtual servers.
aci_aaa_user                                         Manage AAA users (aaa:User)
aci_aaa_user_certificate                             Manage AAA user certificates (aaa:UserCert)
aci_access_port_to_interface_policy_leaf_profile     Manage Fabric interface policy leaf profile interface selectors (infra:HPortS, ...
aci_aep                                              Manage attachable Access Entity Profile (AEP) objects (infra:AttEntityP, infra:...
aci_aep_to_domain                                    Bind AEPs to Physical or Virtual Domains (infra:RsDomP)
aci_ap                                               Manage top level Application Profile (AP) objects (fv:Ap)
aci_bd                                               Manage Bridge Domains (BD) objects (fv:BD)
aci_bd_subnet                                        Manage Subnets (fv:Subnet)
aci_bd_to_l3out                                      Bind Bridge Domain to L3 Out (fv:RsBDToOut)
aci_config_rollback                                  Provides rollback and rollback preview functionality (config:ImportP)
aci_config_snapshot                                  Manage Config Snapshots (config:Snapshot, config:ExportP)
aci_contract                                         Manage contract resources (vz:BrCP)
aci_contract_subject                                 Manage initial Contract Subjects (vz:Subj)
aci_contract_subject_to_filter                       Bind Contract Subjects to Filters (vz:RsSubjFiltAtt)
aci_domain                                           Manage physical, virtual, bridged, routed or FC domain profiles (phys:DomP, vmm...
aci_domain_to_encap_pool                             Bind Domain to Encap Pools (infra:RsVlanNs)
aci_domain_to_vlan_pool                              Bind Domain to VLAN Pools (infra:RsVlanNs)
aci_encap_pool                                       Manage encap pools (fvns:VlanInstP, fvns:VxlanInstP, fvns:VsanInstP)
aci_encap_pool_range                                 Manage encap ranges assig


4.) To list about any particular module.

 [root@ansimaster ~]# ansible-doc ping
> PING    (/usr/lib/python2.7/site-packages/ansible/modules/system/ping.py)

        A trivial test module, this module always returns `pong' on successful contact. It does not make
        sense in playbooks, but it is useful from `/usr/bin/ansible' to verify the ability to login and that
        a usable Python is configured. This is NOT ICMP ping, this is just a trivial test module that
        requires Python on the remote-node. For Windows targets, use the [win_ping] module instead. For
        Network targets, use the [net_ping] module instead.

OPTIONS (= is mandatory):

- data
        Data to return for the `ping' return value.
        If this parameter is set to `crash', the module will cause an exception.
        [Default: pong]


NOTES:
      * For Windows targets, use the [win_ping] module instead.
      * For Network targets, use the [net_ping] module instead.


AUTHOR: Ansible Core Team, Michael DeHaan
        METADATA:
          status:
          - stableinterface
          supported_by: core

==== snip ====>

5.) Try to install any package using ansible command line.

[root@ansimaster ~]# ansible webservers -m yum -a "name=httpd state=present" -s
[DEPRECATION WARNING]: The sudo command line option has been deprecated in favor of the "become" command line arguments. This feature
will be removed in version 2.9. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
192.168.159.142 | CHANGED => {
    "ansible_facts": {
        "pkg_mgr": "yum"
    },
    "changed": true,
    "msg": "",
    "rc": 0,
    "results": [
        "Loaded plugins: fastestmirror, langpacks\nLoading mirror speeds from cached hostfile\n * base: mirror.nbrc.ac.in\n * epel: ftp.jaist.ac.jp\n * extras: mirror.nbrc.ac.in\n * updates: mirror.nbrc.ac.in\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.4.6-89.el7.centos will be installed\n--> Processing Dependency: httpd-tools = 2.4.6-89.el7.centos for package: httpd-2.4.6-89.el7.centos.x86_64\n--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-89.el7.centos.x86_64\n--> Running transaction check\n---> Package httpd-tools.x86_64 0:2.4.6-89.el7.centos will be installed\n---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package           Arch         Version                     Repository     Size\n================================================================================\nInstalling:\n httpd             x86_64       2.4.6-89.el7.centos         updates       2.7 M\nInstalling for dependencies:\n httpd-tools       x86_64       2.4.6-89.el7.centos         updates        90 k\n mailcap           noarch       2.1.41-2.el7                base           31 k\n\nTransaction Summary\n================================================================================\nInstall  1 Package (+2 Dependent packages)\n\nTotal download size: 2.8 M\nInstalled size: 9.6 M\nDownloading packages:\n--------------------------------------------------------------------------------\nTotal                                              2.0 MB/s | 2.8 MB  00:01     \nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n  Installing : mailcap-2.1.41-2.el7.noarch                                  1/3 \n  Installing : httpd-tools-2.4.6-89.el7.centos.x86_64                       2/3 \n  Installing : httpd-2.4.6-89.el7.centos.x86_64                             3/3 \n  Verifying  : httpd-tools-2.4.6-89.el7.centos.x86_64                       1/3 \n  Verifying  : mailcap-2.1.41-2.el7.noarch                                  2/3 \n  Verifying  : httpd-2.4.6-89.el7.centos.x86_64                             3/3 \n\nInstalled:\n  httpd.x86_64 0:2.4.6-89.el7.centos                                            \n\nDependency Installed:\n  httpd-tools.x86_64 0:2.4.6-89.el7.centos     mailcap.noarch 0:2.1.41-2.el7    \n\nComplete!\n"
    ]
}
[root@ansimaster ~]#





6.) Go to client side and check httpd package should be installed

[root@localhost ~]# rpm -qa httpd
httpd-2.4.6-89.el7.centos.x86_64
[root@localhost ~]#
[root@localhost ~]# rpm -qi httpd-2.4.6-89.el7.centos.x86_64
Name        : httpd
Version     : 2.4.6
Release     : 89.el7.centos
Architecture: x86_64
Install Date: Wed 01 May 2019 06:17:00 AM EDT
Group       : System Environment/Daemons
Size        : 9817301
License     : ASL 2.0
Signature   : RSA/SHA256, Mon 29 Apr 2019 11:45:07 AM EDT, Key ID 24c6a8a7f4a80eb5
Source RPM  : httpd-2.4.6-89.el7.centos.src.rpm
Build Date  : Wed 24 Apr 2019 09:48:37 AM EDT
Build Host  : x86-02.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://httpd.apache.org/
Summary     : Apache HTTP Server
Description :
The Apache HTTP Server is a powerful, efficient, and extensible
web server.

7.)Create user

[root@localhost ~]# id anuj
id: anuj: no such user

[root@ansimaster ~]# ansible webservers -m user -a "name=anuj password=anuj" -s
[DEPRECATION WARNING]: The sudo command line option has been deprecated in favor of the "become" command line arguments. This feature
will be removed in version 2.9. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
 [WARNING]: The input password appears not to have been hashed. The 'password' argument must be encrypted for this module to work
properly.

192.168.159.142 | CHANGED => {
    "append": false,
    "changed": true,
    "comment": "",
    "group": 1002,
    "home": "/home/********",
    "move_home": false,
    "name": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
    "password": "NOT_LOGGING_PASSWORD",
    "shell": "/bin/bash",
    "state": "present",
    "uid": 1002
}
[root@ansimaster ~]#


[root@localhost ~]# id anuj
uid=1002(anuj) gid=1002(anuj) groups=1002(anuj)
[root@localhost ~]#


Managing Service from command line:
==================================

On client currently httpd service is stopped

[root@web1 home]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:httpd(8)
           man:apachectl(8)

May 01 10:06:20 web1 systemd[1]: Starting The Apache HTTP Server...
May 01 10:06:20 web1 httpd[9509]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, usin... message
May 01 10:06:20 web1 systemd[1]: Started The Apache HTTP Server.
May 01 10:07:26 web1 systemd[1]: Stopping The Apache HTTP Server...
May 01 10:07:27 web1 systemd[1]: Stopped The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@web1 home]#
[root@web1 home]#

============================
Now try to start it from Ansible server
============================

[root@ansimaster ~]# ansible webservers -m service -a "name=httpd state=started" -s
[DEPRECATION WARNING]: The sudo command line option has been deprecated in favor of the "become" command line arguments. This feature
will be removed in version 2.9. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
192.168.159.142 | CHANGED => {
    "changed": true,
    "name": "httpd",
    "state": "started",
    "status": {
        "ActiveEnterTimestampMonotonic": "0",
        "ActiveExitTimestampMonotonic": "0",
        "ActiveState": "inactive",
        "After": "basic.target -.mount remote-fs.target systemd-journald.socket nss-lookup.target system.slice tmp.mount network.target",
        "AllowIsolate": "no",
        "AssertResult": "no",
        "AssertTimestampMonotonic": "0",
        "Before": "shutdown.target",
        "BlockIOAccounting": "no",
        "BlockIOWeight": "18446744073709551615",
        "CPUAccounting": "no",
        "CPUQuotaPerSecUSec": "infinity",
        "CPUSchedulingPolicy": "0",
        "CPUSchedulingPriority": "0",
        "CPUSchedulingResetOnFork": "no",
        "CPUShares": "18446744073709551615",
        "CanIsolate": "no",
        "CanReload": "yes",
        "CanStart": "yes",
        "CanStop": "yes",
        "CapabilityBoundingSet": "18446744073709551615",
        "ConditionResult": "no",
        "ConditionTimestampMonotonic": "0",
        "Conflicts": "shutdown.target",
        "ControlPID": "0",
        "DefaultDependencies": "yes",
        "Delegate": "no",
        "Description": "The Apache HTTP Server",
        "DevicePolicy": "auto",
        "Documentation": "man:httpd(8) man:apachectl(8)",
        "EnvironmentFile": "/etc/sysconfig/httpd (ignore_errors=no)",
        "ExecMainCode": "0",
        "ExecMainExitTimestampMonotonic": "0",
        "ExecMainPID": "0",
        "ExecMainStartTimestampMonotonic": "0",
        "ExecMainStatus": "0",
        "ExecReload": "{ path=/usr/sbin/httpd ; argv[]=/usr/sbin/httpd $OPTIONS -k graceful ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }",
        "ExecStart": "{ path=/usr/sbin/httpd ; argv[]=/usr/sbin/httpd $OPTIONS -DFOREGROUND ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }",
        "ExecStop": "{ path=/bin/kill ; argv[]=/bin/kill -WINCH ${MAINPID} ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }",
        "FailureAction": "none",
        "FileDescriptorStoreMax": "0",
        "FragmentPath": "/usr/lib/systemd/system/httpd.service",
        "GuessMainPID": "yes",
        "IOScheduling": "0",
        "Id": "httpd.service",
        "IgnoreOnIsolate": "no",
        "IgnoreOnSnapshot": "no",
        "IgnoreSIGPIPE": "yes",
        "InactiveEnterTimestampMonotonic": "0",
        "InactiveExitTimestampMonotonic": "0",
        "JobTimeoutAction": "none",
        "JobTimeoutUSec": "0",
        "KillMode": "control-group",
        "KillSignal": "18",
        "LimitAS": "18446744073709551615",
        "LimitCORE": "18446744073709551615",
        "LimitCPU": "18446744073709551615",
        "LimitDATA": "18446744073709551615",
        "LimitFSIZE": "18446744073709551615",
        "LimitLOCKS": "18446744073709551615",
        "LimitMEMLOCK": "65536",
        "LimitMSGQUEUE": "819200",
        "LimitNICE": "0",
        "LimitNOFILE": "4096",
        "LimitNPROC": "14891",
        "LimitRSS": "18446744073709551615",
        "LimitRTPRIO": "0",
        "LimitRTTIME": "18446744073709551615",
        "LimitSIGPENDING": "14891",
        "LimitSTACK": "18446744073709551615",
        "LoadState": "loaded",
        "MainPID": "0",
        "MemoryAccounting": "no",
        "MemoryCurrent": "18446744073709551615",
        "MemoryLimit": "18446744073709551615",
        "MountFlags": "0",
        "Names": "httpd.service",
        "NeedDaemonReload": "no",
        "Nice": "0",
        "NoNewPrivileges": "no",
        "NonBlocking": "no",
        "NotifyAccess": "main",
        "OOMScoreAdjust": "0",
        "OnFailureJobMode": "replace",
        "PermissionsStartOnly": "no",
        "PrivateDevices": "no",
        "PrivateNetwork": "no",
        "PrivateTmp": "yes",
        "ProtectHome": "no",
        "ProtectSystem": "no",
        "RefuseManualStart": "no",
        "RefuseManualStop": "no",
        "RemainAfterExit": "no",
        "Requires": "basic.target -.mount",
        "RequiresMountsFor": "/var/tmp",
        "Restart": "no",
        "RestartUSec": "100ms",
        "Result": "success",
        "RootDirectoryStartOnly": "no",
        "RuntimeDirectoryMode": "0755",
        "SameProcessGroup": "no",
        "SecureBits": "0",
        "SendSIGHUP": "no",
        "SendSIGKILL": "yes",
        "Slice": "system.slice",
        "StandardError": "inherit",
        "StandardInput": "null",
        "StandardOutput": "journal",
        "StartLimitAction": "none",
        "StartLimitBurst": "5",
        "StartLimitInterval": "10000000",
        "StartupBlockIOWeight": "18446744073709551615",
        "StartupCPUShares": "18446744073709551615",
        "StatusErrno": "0",
        "StopWhenUnneeded": "no",
        "SubState": "dead",
        "SyslogLevelPrefix": "yes",
        "SyslogPriority": "30",
        "SystemCallErrorNumber": "0",
        "TTYReset": "no",
        "TTYVHangup": "no",
        "TTYVTDisallocate": "no",
        "TimeoutStartUSec": "1min 30s",
        "TimeoutStopUSec": "1min 30s",
        "TimerSlackNSec": "50000",
        "Transient": "no",
        "Type": "notify",
        "UMask": "0022",
        "UnitFilePreset": "disabled",
        "UnitFileState": "disabled",
        "Wants": "system.slice",
        "WatchdogTimestampMonotonic": "0",
        "WatchdogUSec": "0"
    }
}
[root@ansimaster ~]#

==========================================
Now go to clint and check httpd service should be started
==========================================
 [root@web1 home]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-05-01 10:09:58 EDT; 19s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 9967 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─9967 /usr/sbin/httpd -DFOREGROUND
           ├─9969 /usr/sbin/httpd -DFOREGROUND
           ├─9970 /usr/sbin/httpd -DFOREGROUND
           ├─9971 /usr/sbin/httpd -DFOREGROUND
           ├─9972 /usr/sbin/httpd -DFOREGROUND
           └─9973 /usr/sbin/httpd -DFOREGROUND

May 01 10:09:58 web1 systemd[1]: Starting The Apache HTTP Server...
May 01 10:09:58 web1 httpd[9967]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, usin... message
May 01 10:09:58 web1 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@web1 home]#



===========================================
Lets see how to copy files from ansible master to client
===========================================
 [root@ansimaster ~]# echo  "Hello Anuj, this is dummy file" > /tmp/dummy.txt
[root@ansimaster ~]# cat /tmp/dummy.txt
Hello Anuj, this is dummy file
[root@ansimaster ~]#
[root@ansimaster ~]# ansible webservers -m copy -a "src=/tmp/dummy.txt dest=/tmp/dummy.txt" -s
[DEPRECATION WARNING]: The sudo command line option has been deprecated in favor of the "become" command line arguments. This feature
will be removed in version 2.9. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
192.168.159.142 | CHANGED => {
    "changed": true,
    "checksum": "d5a896e4a6e6154bd862f2a183288a0e958789de",
    "dest": "/tmp/dummy.txt",
    "gid": 0,
    "group": "root",
    "md5sum": "f42503fe4c04db3f52c1657e55abdfc2",
    "mode": "0644",
    "owner": "root",
    "secontext": "unconfined_u:object_r:admin_home_t:s0",
    "size": 31,
    "src": "/root/.ansible/tmp/ansible-tmp-1556720163.65-117534200332880/source",
    "state": "file",
    "uid": 0
}
[root@ansimaster ~]#

######
login to client and check file should be created with same content
######
 [root@web1 ~]# cat /tmp/dummy.txt   <=== file is created on client
Hello Anuj, this is dummy file
[root@web1 ~]#


    "mode": "0774",
    "owner": "anuj",
    "path": "/tmp/dummy.txt",
    "secontext": "unconfined_u:object_r:admin_home_t:s0",
    "size": 31,
    "state": "file",
    "uid": 1002
}
[root@ansimaster ~]#

=============================================================
Let`s do some oprations on file.
=============================================================
1.) change file permissions on client:

[root@web1 ~]# ll /tmp/dummy.txt
-rw-r--r--. 1 root root 31 May  1 10:16 /tmp/dummy.txt
[root@web1 ~]#

[root@ansimaster ~]# ansible webservers -m file -a "dest=/tmp/dummy.txt mode=774" -s
[DEPRECATION WARNING]: The sudo command line option has been deprecated in favor of the "become" command line arguments. This feature
will be removed in version 2.9. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
192.168.159.142 | CHANGED => {
    "changed": true,
    "gid": 0,
    "group": "root",
    "mode": "0774",
    "owner": "root",
    "path": "/tmp/dummy.txt",
    "secontext": "unconfined_u:object_r:admin_home_t:s0",
    "size": 31,
    "state": "file",
    "uid": 0
}
[root@ansimaster ~]#


[root@web1 ~]# ll /tmp/dummy.txt   <====== permissions has been changed on client
-rwxrwxr--. 1 root root 31 May  1 10:16 /tmp/dummy.txt
[root@web1 ~]#



2.) Now change owner and group for /tmp/dummy

[root@web1 ~]# ll /tmp/dummy.txt
-rwxrwxr--. 1 root root 31 May  1 10:16 /tmp/dummy.txt

[root@ansimaster ~]# ansible webservers -m file -a "dest=/tmp/dummy.txt owner=anuj group=apache" -s
[DEPRECATION WARNING]: The sudo command line option has been deprecated in favor of the "become" command line arguments. This feature
will be removed in version 2.9. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
192.168.159.142 | CHANGED => {
    "changed": true,
    "gid": 48,
    "group": "apache",
    "mode": "0774",
    "owner": "anuj",
    "path": "/tmp/dummy.txt",
    "secontext": "unconfined_u:object_r:admin_home_t:s0",
    "size": 31,
    "state": "file",
    "uid": 1002
}
[root@ansimaster ~]#


[root@web1 ~]# ll /tmp/dummy.txt
-rwxrwxr--. 1 anuj apache 31 May  1 10:16 /tmp/dummy.txt  <==== owner and group changed
[root@web1 ~]#


3.) lets try to create directory on clint

[root@web1 ~]# ls -ld /tmp/testdir
ls: cannot access /tmp/testdir: No such file or directory
[root@web1 ~]#
[root@web1 ~]#

[root@ansimaster ~]#  ansible webservers -m file -a "dest=/tmp/testdir mode=764 owner=root group=apache state=directory" -s
[DEPRECATION WARNING]: The sudo command line option has been deprecated in favor of the "become" command line arguments. This feature
will be removed in version 2.9. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
192.168.159.142 | CHANGED => {
    "changed": true,
    "gid": 48,
    "group": "apache",
    "mode": "0764",
    "owner": "root",
    "path": "/tmp/testdir",
    "secontext": "unconfined_u:object_r:user_tmp_t:s0",
    "size": 6,
    "state": "directory",
    "uid": 0
}
[root@ansimaster ~]#


[root@web1 ~]# ls -ld /tmp/testdir
drwxrw-r--. 2 root apache 6 May  1 10:51 /tmp/testdir  <======== directory has been created
[root@web1 ~]#

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

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