Thursday, May 30, 2019

Play book to install multiple packages then restart services using with_items:

Writing a play book to install multiple packages using vars and then restart  services using  with_items:
Starting multiple services using with_items:
You can use the with_items parameter to control multiple services in a single task.
Note: Make sure the {{ item }} is within quotes, and the with_items block need to be intended at the level of module name in our case its -here systemd. The following example will restart nfs-utils and httpd, a daemon reload before it restarts the service.


Now lets try to install httpd and nfs-utils on web client

[root@web1 ~]# yum list nfs-utils httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.nbrc.ac.in
 * epel: sg.fedora.ipserverone.com
 * extras: mirror.nbrc.ac.in
 * updates: mirror.nbrc.ac.in
Available Packages
httpd.x86_64                                                   2.4.6-89.el7.centos                                               updates
nfs-utils.x86_64                                               1:1.3.0-0.61.el7                                                  base
[root@web1 ~]#


[root@ansimaster playbooks]# cat multipalepacke.yml
# Simple anisble playbook to install multiple packages.
-
 name: Play to install multiple pacakges
 hosts: webservers
 tasks:
  - name: Ensure list of package present on web client
    yum:
      name: "{{Packages}}"
    vars:
      Packages:
      - nfs-utils
      - httpd

  - name: start services for nfs and httpd
    systemd:
      name: "{{ item }}"
      state: restarted
      daemon_reload: yes
    with_items:
      - 'httpd'
      - 'nfs-utils'
[root@ansimaster playbooks]#
[root@ansimaster playbooks]#

[root@ansimaster playbooks]#  ansible-playbook multipalepacke.yml --syntax-check

playbook: multipalepacke.yml
[root@ansimaster playbooks]#
[root@ansimaster playbooks]#  ansible-playbook multipalepacke.yml

PLAY [Play to install multiple pacakges] ***********************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************
ok: [192.168.159.142]

TASK [Ensure list of package present on web client] ************************************************************************************
changed: [192.168.159.142]

TASK [start services for nfs and httpd] ************************************************************************************************
changed: [192.168.159.142] => (item=httpd)
changed: [192.168.159.142] => (item=nfs-utils)

PLAY RECAP *****************************************************************************************************************************
192.168.159.142            : ok=3    changed=2    unreachable=0    failed=0





==================================================================
Now go to web client and check for packages installed or not
==================================================================

[root@web1 ~]# yum list nfs-utils httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.nbrc.ac.in
 * epel: sg.fedora.ipserverone.com
 * extras: mirror.nbrc.ac.in
 * updates: mirror.nbrc.ac.in
Installed Packages
httpd.x86_64                                                  2.4.6-89.el7.centos                                               @updates
nfs-utils.x86_64                                              1:1.3.0-0.61.el7                                                  @base
[root@web1 ~]#

============================================================================================================
Cheears packages has been installed on client now lets quickly check for services too......
============================================================================================================
[root@web1 ~]# systemctl status httpd; systemctl status nfs-utils;
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2019-05-30 11:15:04 EDT; 2min 55s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 15245 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─15245 /usr/sbin/httpd -DFOREGROUND
           ├─15247 /usr/sbin/httpd -DFOREGROUND
           ├─15248 /usr/sbin/httpd -DFOREGROUND
           ├─15249 /usr/sbin/httpd -DFOREGROUND
           ├─15250 /usr/sbin/httpd -DFOREGROUND
           └─15251 /usr/sbin/httpd -DFOREGROUND

May 30 11:15:04 web1 systemd[1]: Starting The Apache HTTP Server...
May 30 11:15:04 web1 systemd[1]: Started The Apache HTTP Server.
May 30 11:15:04 web1 httpd[15245]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, usi... message
Hint: Some lines were ellipsized, use -l to show in full.
● nfs-utils.service - NFS server and client services
   Loaded: loaded (/usr/lib/systemd/system/nfs-utils.service; static; vendor preset: disabled)
   Active: active (exited) since Thu 2019-05-30 11:15:05 EDT; 2min 54s ago
  Process: 15347 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 15347 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/nfs-utils.service

May 30 11:15:04 web1 systemd[1]: Stopping NFS server and client services...
May 30 11:15:04 web1 systemd[1]: Starting NFS server and client services...
May 30 11:15:05 web1 systemd[1]: Started NFS server and client services.
[root@web1 ~]#

=============================================================================
waooo services has been started by its own by ansible master server
=============================================================================


Friday, May 24, 2019

Playbook to install package and start services


==================================================
Playbook to install package and start services
==================================================
[root@ansimaster playbooks]# cat installpackage.yml
#Simple Ansible playbook
-
  name: Play 1
  hosts: webservers
  tasks:
    - name: Install httpd package on webservers
      yum:
         name: httpd
         state: present

    - name: Start web service
      service:
         name: httpd
         state: started
[root@ansimaster playbooks]#
[root@ansimaster playbooks]#
[root@ansimaster playbooks]# ansible-playbook installpackage.yml --syntax-check

playbook: installpackage.yml
[root@ansimaster playbooks]#
[root@ansimaster playbooks]#
[root@ansimaster playbooks]# ansible-playbook installpackage.yml

PLAY [Play 1] **************************************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************
ok: [192.168.159.142]

TASK [Install httpd package on webservers] *********************************************************************************************
changed: [192.168.159.142]

TASK [Start web service] ***************************************************************************************************************
changed: [192.168.159.142]

PLAY RECAP *****************************************************************************************************************************
192.168.159.142            : ok=3    changed=2    unreachable=0    failed=0

[root@ansimaster playbooks]#


===================================================
On Clint side httpd status  before running playbook
===================================================

[root@web1 ~]# yum list httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.nbrc.ac.in
 * epel: sg.fedora.ipserverone.com
 * extras: mirror.nbrc.ac.in
 * updates: mirror.nbrc.ac.in
Available Packages
httpd.x86_64                                                 2.4.6-89.el7.centos                                                 updates
[root@web1 ~]#
[root@web1 ~]#

[root@web1 ~]# systemctl status httpd
Unit httpd.service could not be found.
[root@web1 ~]#



===================================================
On Clint side httpd status after running playbook
===================================================

[root@web1 ~]# yum list httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.nbrc.ac.in
 * epel: sg.fedora.ipserverone.com
 * extras: mirror.nbrc.ac.in
 * updates: mirror.nbrc.ac.in
Installed Packages
httpd.x86_64                                                2.4.6-89.el7.centos                                                 @updates
[root@web1 ~]#


[root@web1 ~]# 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 Fri 2019-05-24 12:04:32 EDT; 9s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 7994 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─7994 /usr/sbin/httpd -DFOREGROUND
           ├─7995 /usr/sbin/httpd -DFOREGROUND
           ├─7996 /usr/sbin/httpd -DFOREGROUND
           ├─7997 /usr/sbin/httpd -DFOREGROUND
           ├─7998 /usr/sbin/httpd -DFOREGROUND
           └─7999 /usr/sbin/httpd -DFOREGROUND

May 24 12:04:32 web1 systemd[1]: Starting The Apache HTTP Server...
May 24 12:04:32 web1 httpd[7994]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, usin... message
May 24 12:04:32 web1 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@web1 ~]#

If your server has static ip and its getting change by its own


============================================
If your server has static ip and its getting change by its own 
============================================

 dracut -vf
 dracut -vf /boot/initramfs-3.10.0-514.10.2.el7.x86_64.img
 dracut -f /boot/initramfs-3.10.0-514.10.2.el7.x86_64.img
 grub2-mkconfig -o /boot/grub2/grub.cfg
 init 6

How to Copy file from remote server to local Anisble server

===============================================================
How to Copy file from remote server to local Anisble server
===============================================================

Let`s take backup of ens33 network configuration file on ansible server

Following file is on ansible web client

[root@web1 network-scripts]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO="static"
NAME=ens33
UUID=0ca5a92f-d841-4f82-a69b-56c6a52657e5
IPADDR="192.168.159.142"
NETMASK="255.255.255.0"
GATEWAY="192.168.159.2"
DEVICE=ens33
ONBOOT=yes
[root@web1 network-scripts]#

====================================================================================================
Now lets write playbook which will copy file from web1 ansible client to ansible server localy
====================================================================================================
[root@ansimaster playbooks]# cat fetchremotefile.yml
- hosts: webservers
  tasks:
  - name: Ansible fetch files from remote server to the local machine under /tmp/web1/ using Ansible fetch module
    fetch:
       src: /etc/sysconfig/network-scripts/ifcfg-ens33
       dest: /tmp/web1/
[root@ansimaster playbooks]#
[root@ansimaster playbooks]#
[root@ansimaster playbooks]# ansible-playbook -v fetchremotefile.yml --syntax-check
Using /etc/ansible/ansible.cfg as config file
/etc/ansible/hosts did not meet host_list requirements, check plugin documentation if this is unexpected
/etc/ansible/hosts did not meet script requirements, check plugin documentation if this is unexpected

playbook: fetchremotefile.yml
[root@ansimaster playbooks]#
[root@ansimaster playbooks]# ansible-playbook -v fetchremotefile.yml
Using /etc/ansible/ansible.cfg as config file
/etc/ansible/hosts did not meet host_list requirements, check plugin documentation if this is unexpected
/etc/ansible/hosts did not meet script requirements, check plugin documentation if this is unexpected

PLAY [webservers] **********************************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************
ok: [192.168.159.142]

TASK [Ansible fetch files from remote server to the local machine under /tmp/web1/ using Ansible fetch module] **********************
ok: [192.168.159.142] => {"changed": false, "checksum": "9fdc4631156b259899e953b5f404210da39ca1cb", "dest": "/tmp/web1/192.168.159.142/etc/sysconfig/network-scripts/ifcfg-ens33", "file": "/etc/sysconfig/network-scripts/ifcfg-ens33", "md5sum": "1d434556162da86401f9945f74fd4929"}

PLAY RECAP *****************************************************************************************************************************
192.168.159.142            : ok=2    changed=0    unreachable=0    failed=0

[root@ansimaster playbooks]#



=====================================================================================================================
Now check network configuration file of web1 client should preset on ansible server under /tmp/web1/
=====================================================================================================================
[root@ansimaster ~]# ls -ld /tmp/web1
drwxr-xr-x. 3 root root 29 May 22 09:25 /tmp/web1
[root@ansimaster ~]#

[root@ansimaster network-scripts]# cat /tmp/web1/192.168.159.142/etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO="static"
NAME=ens33
UUID=0ca5a92f-d841-4f82-a69b-56c6a52657e5
IPADDR="192.168.159.142"
NETMASK="255.255.255.0"
GATEWAY="192.168.159.2"
DEVICE=ens33
ONBOOT=yes
[root@ansimaster network-scripts]#

Saturday, May 4, 2019

Managing config from ansible server to client and then do conditional restart of service



[root@ansimaster conf]# cat /root/apache_playbook2.yml
---
- hosts: webservers
  become: true
  become_user: root
  tasks:
  - name: Install httpa package
    yum: name=httpd state=present
  - name: Start appache services
    service: name=httpd state=started
  - name: Deploying httpd conf
    copy: src=/ansible/config/httpd/conf/ dest=/usr/share/httpd/noindex/
    notify: restart httpd
  handlers:
  - name: restart httpd
    service: name=httpd state=restarted


#notify module executed only if file get copied to target host only and then restart httpd

[root@ansimaster conf]#

[root@ansimaster conf]# diff index.html index.html.bkp
68c68
<         <h1> Welcome mylinuxfriends 123..</h1>  <=========== we have added new contents in config.
---
>         <h1> Testing 123..</h1>
[root@ansimaster conf]#

[root@ansimaster conf]# ansible-playbook /root/apache_playbook2.yml <======== run your playbook


**** Now go to your client and check new content should be copied to target nodes and httpd should be running ****

[root@web1 images]# grep -i welcome /usr/share/httpd/noindex/index.html
          <h1> Welcome mylinuxfriends 123..</h1>
                                        <p>To prevent this page from ever being used, follow the instructions in the file <tt>/etc/httpd/conf.d/welcome.conf</tt>.</p>
[root@web1 images]#
[root@web1 images]# 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 Sat 2019-05-04 12:31:30 EDT; 20min ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 23862 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
 Main PID: 23866 (httpd)
   Status: "Total requests: 5; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─23866 /usr/sbin/httpd -DFOREGROUND
           ├─23868 /usr/sbin/httpd -DFOREGROUND
           ├─23869 /usr/sbin/httpd -DFOREGROUND
           ├─23870 /usr/sbin/httpd -DFOREGROUND
           ├─23871 /usr/sbin/httpd -DFOREGROUND
           ├─23872 /usr/sbin/httpd -DFOREGROUND
           ├─23882 /usr/sbin/httpd -DFOREGROUND
           ├─23883 /usr/sbin/httpd -DFOREGROUND
           └─23884 /usr/sbin/httpd -DFOREGROUND

May 04 12:31:30 web1 systemd[1]: Starting The Apache HTTP Server...
May 04 12:31:30 web1 httpd[23866]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, usi... message
May 04 12:31:30 web1 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@web1 images]#

Writing playbook in ansible

Now lets write 1st playbook.
============================

[root@ansimaster ~]# cat apache_playbook.yml
---
- hosts: webservers
  become: true
  become_user: root
  tasks:
  - name: Install httpa package
    yum: name=httpd state=present
  - name: Start appache services
    service: name=httpd state=started
   
[root@ansimaster ~]#

===================================================================
We can check if there is any error in playboot using --sytax-check
===================================================================
[root@ansimaster ~]# ansible-playbook apache_playbook.yml --syntax-check

playbook: apache_playbook.yml
[root@ansimaster ~]#
[root@ansimaster ~]#
[root@ansimaster ~]#
[root@ansimaster ~]#
[root@ansimaster ~]#
[root@ansimaster ~]#
===================================================================
If you want to see on how many hosts this playbook will run
===================================================================
[root@ansimaster ~]# ansible-playbook apache_playbook.yml --list-hosts

playbook: apache_playbook.yml

  play #1 (webservers): webservers      TAGS: []
    pattern: [u'webservers']
    hosts (1):
      192.168.159.142
[root@ansimaster ~]#

===================================================================
Now run your 1st playbook
===================================================================

[root@ansimaster ~]# ansible-playbook apache_playbook.yml

PLAY [webservers] **********************************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************
ok: [192.168.159.142]

TASK [Install httpa package] ***********************************************************************************************************
changed: [192.168.159.142]

TASK [Start appache services] **********************************************************************************************************
changed: [192.168.159.142]

PLAY RECAP *****************************************************************************************************************************
192.168.159.142            : ok=3    changed=2    unreachable=0    failed=0

[root@ansimaster ~]#


****  Now go to the client and check httd package should be installed and services should be running *****

[root@web1 ~]# yum list httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.mirrors.estointernet.in
 * epel: repos.del.extreme-ix.org
 * extras: repos.del.extreme-ix.org
 * updates: repos.del.extreme-ix.org
Installed Packages
httpd.x86_64                                                2.4.6-89.el7.centos                                                 @updates
[root@web1 ~]#
[root@web1 ~]# 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 Sat 2019-05-04 10:43:22 EDT; 29s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 14664 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─14664 /usr/sbin/httpd -DFOREGROUND
           ├─14667 /usr/sbin/httpd -DFOREGROUND
           ├─14668 /usr/sbin/httpd -DFOREGROUND
           ├─14669 /usr/sbin/httpd -DFOREGROUND
           ├─14670 /usr/sbin/httpd -DFOREGROUND
           └─14671 /usr/sbin/httpd -DFOREGROUND

May 04 10:43:21 web1 systemd[1]: Starting The Apache HTTP Server...
May 04 10:43:22 web1 httpd[14664]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, usi... message
May 04 10:43:22 web1 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@web1 ~]#

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

kubernetes Pod Scheduling

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