Sunday, July 14, 2019

# Gathering Ansible facts from remote server


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

You can get remote severs facts using ad-hoc commands.
============================================

[root@ansimaster:/etc/ansible]#ansible webservers -m setup -a 'filter=ansible_dns'
192.168.122.50 | SUCCESS => {
    "ansible_facts": {
        "ansible_dns": {
            "nameservers": [
                "192.168.122.1"
            ],
            "search": [
                "default"
            ]
        }
    },
    "changed": false
}
[root@ansimaster:/etc/ansible]# ansible webservers -m setup -a 'filter=ansible_bios'
192.168.122.50 | SUCCESS => {
    "ansible_facts": {},
    "changed": false
}
[root@ansimaster:/etc/ansible]#
[root@ansimaster:/etc/ansible]# \ ansible 03:16 PM]
[root@ansimaster:/etc/ansible]# \ ansible 03:16 PM]ansible webservers -m setup -a 'filter=ansible_bios_version'
192.168.122.50 | SUCCESS => {
    "ansible_facts": {
        "ansible_bios_version": "0.5.1"
    },
    "changed": false
}
[root@ansimaster:/etc/ansible]# \ ansible 03:17 PM]ansible webservers -m setup -a 'filter=ansible_bios_date'
192.168.122.50 | SUCCESS => {
    "ansible_facts": {
        "ansible_bios_date": "01/01/2011"
    },
    "changed": false
}
[root@ansimaster:/etc/ansible]#
[root@ansimaster:/etc/ansible]# ansible webservers -m setup -a 'filter=ansible_cmdline'
192.168.122.50 | SUCCESS => {
    "ansible_facts": {
        "ansible_cmdline": {
            "BOOT_IMAGE": "/vmlinuz-3.10.0-514.el7.x86_64",
            "LANG": "en_US.UTF-8",
            "crashkernel": "auto",
            "quiet": true,
            "rd.lvm.lv": "cl_web1/swap",
            "rhgb": true,
            "ro": true,
            "root": "/dev/mapper/cl_web1-root"
        }
    },
    "changed": false
}
# Using Facts, in ansible playbook

[root@ansimaster:~/ansiroot/playbook]# vi playbook1_remote_facts.yml
---
 - name: Playbook that will gather facts from webservers.
   hosts: webservers
   tasks:
    - name: Gethering memory details from webservers.
      debug:
        msg: >
          Them memory details of webservers is: {{ ansible_memory_mb }}
          is {{ ansible_memory_mb }}

### End of play book "playbook1_remote_facts.yml  #####


   =========================================
       Now lets check and run this playbook
   =========================================

[root@ansimaster:~/ansiroot/playbook]# \ playbook 02:54 PM]ansible-playbook playbook1_remote_facts.yml -C

PLAY [Playbook that will gather facts from webservers.] *****************************************************************************************************************

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

TASK [Gethering memory details from webservers.] ************************************************************************************************************************
ok: [192.168.122.50] => {
    "msg": "Them memory details of webservers is: {u'real': {u'total': 2775, u'free': 1244, u'used': 1531}, u'swap': {u'cached': 0, u'total': 1023, u'used': 0, u'free': 1023}, u'nocache': {u'used': 607, u'free': 2168}} is {u'real': {u'total': 2775, u'free': 1244, u'used': 1531}, u'swap': {u'cached': 0, u'total': 1023, u'used': 0, u'free': 1023}, u'nocache': {u'used': 607, u'free': 2168}}\n"
}

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

[root@ansimaster:~/ansiroot/playbook]# \ playbook 02:54 PM]ansible-playbook playbook1_remote_facts.yml

PLAY [Playbook that will gather facts from webservers.] *****************************************************************************************************************

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

TASK [Gethering memory details from webservers.] ************************************************************************************************************************
ok: [192.168.122.50] => {
    "msg": "Them memory details of webservers is: {u'real': {u'total': 2775, u'free': 1244, u'used': 1531}, u'swap': {u'cached': 0, u'total': 1023, u'used': 0, u'free': 1023}, u'nocache': {u'used': 607, u'free': 2168}} is {u'real': {u'total': 2775, u'free': 1244, u'used': 1531}, u'swap': {u'cached': 0, u'total': 1023, u'used': 0, u'free': 1023}, u'nocache': {u'used': 607, u'free': 2168}}\n"
}

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

[root@ansimaster:~/ansiroot/playbook]#

using blocks in ansjble

#Using blocks in ansible, Playbook to install configure apache.
================================================


[root@ansimaster:~/ansiroot/playbook]# vi mange_web_intranet_2.yml
---
 - name: Playbook to install configure and verify web and database status.
   hosts: webservers
   tasks:
   - block:
     - name: installing httpd package.
       yum:
         name: httpd
         state: present
     - name: installtaling firewalld
       yum:
         name: firewalld
         state: present
     - name: installtaling mariadb-server
       yum:
        name: mariadb-server
        state: present

     - name:
       yum:
        name: php
        state: present
     - name:
       yum:
        name: php-mysql
        state: present

   - block:
     - name: Friewalld permits http service.
       firewalld:
        service: http
        permanent: true
        state: enabled
        immediate: yes

     - name: Starting web service.
       service:
        name: httpd
        enabled: true
       state: started

   - block:
     - name: Deploying http config.
       copy: src=/root/ansiroot/config/httpd/ dest=/usr/share/httpd/noindex/

       notify:
        - restart httpd
     - name: ensure httpd is running
       service:
         name: httpd
         state: started
   handlers:
      - name: restart httpd
        service:
         name: httpd
         state: restarted

 - name: Playbook to test Mylinuxfriend blog working in intranet.
   hosts: webservers
   tasks:
    - name: connected to intranet...!
      uri:
        url: http://192.168.122.50
        status_code: 200

## END of playbook mange_web_intranet_2.yml ######
wq!

[root@ansimaster:~/ansiroot/playbook]#

============================
  Now lets check your playbook syntex
============================

[root@ansimaster:~/ansiroot/playbook]# ansible-playbook mange_web_intranet_2.yml -C
 [WARNING]: Ignoring invalid attribute: state


PLAY [Playbook to install configure and verify web and database status.] ************************************************************************************************

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

TASK [installing httpd package.] ****************************************************************************************************************************************
ok: [192.168.122.50]

TASK [installtaling firewalld] ******************************************************************************************************************************************
ok: [192.168.122.50]

TASK [installtaling mariadb-server] *************************************************************************************************************************************
ok: [192.168.122.50]

TASK [yum] **************************************************************************************************************************************************************
ok: [192.168.122.50]

TASK [yum] **************************************************************************************************************************************************************
ok: [192.168.122.50]

TASK [Friewalld permits http service.] **********************************************************************************************************************************
ok: [192.168.122.50]

TASK [Starting web service.] ********************************************************************************************************************************************
ok: [192.168.122.50]

TASK [Deploying http config.] *******************************************************************************************************************************************
changed: [192.168.122.50]

TASK [ensure httpd is running] ******************************************************************************************************************************************
ok: [192.168.122.50]

RUNNING HANDLER [restart httpd] *****************************************************************************************************************************************
changed: [192.168.122.50]

PLAY [Playbook to test Mylinuxfriend blog working in intranet.] *********************************************************************************************************

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

TASK [connected to intranet...!] ****************************************************************************************************************************************
skipping: [192.168.122.50]

PLAY RECAP **************************************************************************************************************************************************************
192.168.122.50             : ok=12   changed=2    unreachable=0    failed=0  

[root@ansimaster:~/ansiroot/playbook]#

===========================================================
Yeah its good and good to execute, just remove -C and hit the magic button ENTER
===========================================================
# Ansible gathering  facts from remote servers.
=============================

======================================
getting facts from remote servers
======================================

[root@ansimaster:~/ansiroot/playbook]# ansible webservers -m setup | grep -A15  memory
        "ansible_memory_mb": {
            "nocache": {
                "free": 2177,
                "used": 598
            },
            "real": {
                "free": 1261,
                "total": 2775,
                "used": 1514
            },
            "swap": {
                "cached": 0,
                "free": 1023,
                "total": 1023,
                "used": 0
            }

==================================
listing complete pre-defined facts
==================================

[root@ansimaster:~/ansiroot/playbook]# ansible webservers -m setup
192.168.122.50 | SUCCESS => {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "192.168.124.1",
            "192.168.122.31",
            "192.168.122.50"
        ],
        "ansible_all_ipv6_addresses": [
            "fe80::3874:e8e6:a1cd:5e9",
            "fe80::5054:ff:fe75:cb41"
        ],
        "ansible_apparmor": {
            "status": "disabled"
        },
        "ansible_architecture": "x86_64",
        "ansible_bios_date": "01/01/2011",
        "ansible_bios_version": "0.5.1",
        "ansible_cmdline": {
            "BOOT_IMAGE": "/vmlinuz-3.10.0-514.el7.x86_64",
            "LANG": "en_US.UTF-8",
            "crashkernel": "auto",
            "quiet": true,
            "rd.lvm.lv": "cl_web1/swap",
            "rhgb": true,
            "ro": true,
            "root": "/dev/mapper/cl_web1-root"
        },
        "ansible_date_time": {

----- Output is Snip-----


----- Output is Snip-----


            "hw_timestamp_filters": [],
            "ipv4": {
                "address": "192.168.122.50",
                "broadcast": "192.168.122.255",
                "netmask": "255.255.255.0",
                "network": "192.168.122.0"
            },
            "ipv6": [
                {
                    "address": "fe80::5054:ff:fe75:cb41",
                    "prefix": "64",
                    "scope": "link"
                }
            ],
            "macaddress": "52:54:00:75:cb:41",
            "module": "virtio_net",
            "mtu": 1500,
            "pciid": "virtio0",
            "promisc": false,
            "timestamping": [
                "rx_software",
                "software"
            ],
            "type": "ether"
        },
        "ansible_fips": false,
        "ansible_form_factor": "Other",
        "ansible_fqdn": "web1",
        "ansible_hostname": "web1",
        "ansible_interfaces": [
            "lo",
            "virbr0",
            "virbr0-nic",
            "ens10",
            "eth0"
        ],
        "ansible_kernel": "3.10.0-514.el7.x86_64",
        "ansible_lo": {
            "active": true,
            "device": "lo",


----- Output is Snip-----

Saturday, July 13, 2019

Using VARS in ansible


# Ansible playbook to Install & manage web, firewalld   using VARS.
================================================


[root@ansimaster:~/ansiroot/playbook]# vi  mange_web_using_vars.yml
---
 - name: Install Apache and start the service
   hosts: webservers
   vars:
     web_pkg: httpd
     firewall_pkg: firewalld
     python_pkg: python-httplib2
     web_service: httpd     
     firewall_service: firewalld
     rule: http
  
   tasks:
     - name: installing httpd, firewalld, python-httpdlib2 packages...
       yum:
         name:
           - "{{ firewall_pkg }}"
           - "{{ web_pkg }}"
           - "{{ python_pkg }}"
         state: present

     - name: Starting and Enabling the {{ firewall_pkg }} services
       service:
         name: "{{ firewall_service }}"
         enabled: true
         state: started

     - name: Starting and Enabling the {{ web_service }} services
       service:
         name: "{{ web_service }}"
         enabled: true
         state: started

  
     - name: Creating web conntent to be served
       copy:
         content: " Welcome Mylinuxfriend sponserd by mylinuxfriends.blogspot.com"
         dest: /usr/share/httpd/noindex/index.html
   
     - name: Open the port for {{ rule }}
       firewalld:
         service: "{{ rule }}"
         permanent: true
         state: enabled

 - name: Verify the Apache service
   hosts: webservers
   tasks:
     - name: Ensure the webserver is reachable
       uri:
         url: http://192.168.122.50
         status_code: 200
[root@ansimaster:~/ansiroot/playbook]#






====================================
Now lets check our playbook is good to execute or not.
====================================



[root@ansimaster:~/ansiroot/playbook]# \ playbook 11:52 AM]ansible-playbook mange_web_using_vars.yml -C

PLAY [Install Apache and start the service] **********************************************************************************************

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

TASK [installing httpd, firewalld, python-httpdlib2 packages...] *************************************************************************
changed: [192.168.122.50]

TASK [Starting and Enabling the firewalld services] **************************************************************************************
changed: [192.168.122.50]

TASK [Starting and Enabling the httpd services] ******************************************************************************************
changed: [192.168.122.50]

TASK [Creating web conntent to be served] ************************************************************************************************
changed: [192.168.122.50]

TASK [Open the port for http] ************************************************************************************************************
ok: [192.168.122.50]

PLAY [Verify the Apache service] *********************************************************************************************************

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

TASK [Ensure the webserver is reachable] *************************************************************************************************
skipping: [192.168.122.50]

PLAY RECAP *******************************************************************************************************************************
192.168.122.50             : ok=7    changed=4    unreachable=0    failed=0  

[root@ansimaster:~/ansiroot/playbook]# \ playbook 11:52 AM]

=============================================
Yeah its good and good to execute, just remove -C and hit the magic button ENTER
===============================================


Wednesday, July 10, 2019

Manage firewall to allow http


# Write a Ansible play to manage http, firewalld and deploy http config
=================================================

1.) Install http package and manage its services.

2.) Configure firewalld rule to allow http traffic and manage firewalld.

3.)  deploy http config from ansible master to web clients and restart service
       while there is any config change in http config.

4.) Test wesite should be working in network.

========= lets start ============

 [root@ansimaster:~]# mkdir -p /root/ansiroot/config/httpd/

#Now put you web config file in this directory in our case you will put index.html 

[root@ansimaster:~]# ls -l /root/ansiroot/config/httpd/
total 8
-rw-r--r--. 1 root root 4907 Jul  9 18:30 index.html
[root@ansimaster:~]#




 [root@ansimaster:~]# vi /root/playbook/mange_web_intranet.yml
 ---
  - name: Play book to install httpd package and manage firewall.
    hosts: webservers
    tasks:
      - name: install httpd package and start apache web service.
        yum:
          name: httpd
          state: present

      - name: installing firewalld latest version.
        yum:
          name: firewalld
          state: latest

      - name: Starting web services.
        service:
         name: httpd
         state: started
         enabled: true
   
      - name: Starting Firewalld.
        service:
         name: firewalld
         state: started

      - name: Firewalld permits http service.
        firewalld:
          service: http
          state: enabled
          immediate: yes

    
      - name: Deploying http config.
        copy: src=/root/ansiroot/config/httpd/ dest=/usr/share/httpd/noindex/

        notify:
        - restart httpd
      - name: ensure httpd is running
        service:
          name: httpd
          state: started
    handlers:
        - name: restart httpd
          service:
            name: httpd
            state: restarted

  - name: Playbook to test Mylinuxfriend blog working in intranet.
    hosts: webservers
    tasks:
     - name: connected to intranet...!
       uri:
         url: http://192.168.122.50
         status_code: 200
wq!


============== Now lets check playbook has any error or not =====

 [root@ansimaster:~/playbook]# ansible-playbook mange_web_intranet.yml -C

PLAY [Play book to install httpd package and manage firewall.] ***************************************************************************

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

TASK [install httpd package and start apache web service.] *******************************************************************************
ok: [192.168.122.50]

TASK [installing firewalld latest version.] **********************************************************************************************
ok: [192.168.122.50]

TASK [Starting web services.] ************************************************************************************************************
ok: [192.168.122.50]

TASK [Starting Firewalld.] ***************************************************************************************************************
ok: [192.168.122.50]

TASK [Firewalld permits http service.] ***************************************************************************************************
ok: [192.168.122.50]

TASK [Deploying http config.] ************************************************************************************************************
ok: [192.168.122.50]

TASK [ensure httpd is running] ***********************************************************************************************************
ok: [192.168.122.50]

PLAY [Playbook to test Mylinuxfriend blog working in intranet.] **************************************************************************

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

TASK [connected to intranet...!] *********************************************************************************************************
skipping: [192.168.122.50]

PLAY RECAP *******************************************************************************************************************************
192.168.122.50             : ok=9    changed=0    unreachable=0    failed=0  

[root@ansimaster:~/playbook]#


Now playbook is ready just execute it by removing -C  from above command.

===============  ITS WORKING  ================

Friday, July 5, 2019

# Ansible module and some advance options

# Ansible module and some advance options
Modules:

Command: This module help you to execute commands to the target host, it may be command or script

 ===> chdir:

Following is simple playboot that will display contents of /etc/hosts of webserers.
and you can use chdir sub-module that tells ansible servers to change dir to /etc before doing cat to hosts file   
[root@ansimaster playbooks]# cat date.yml
-
 name: Play 1
 hosts: webservers
 tasks:
   - name: Execute a date command
     command: cat hosts chdir=/etc
[root@ansimaster playbooks]#


 ===> creates

 [root@ansimaster playbooks]# cat date.yml
-
 name: Play 1
 hosts: webservers
 tasks:
   - name: Execute a date command
     command: cat hosts chdir=/etc
   - name: create folder if not exists
     command: mkdir /test_dir creates=true
[root@ansimaster playbooks]#



 [root@ansimaster ~]# ansible --version
ansible 2.7.10
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
[root@ansimaster ~]#


[root@ansimaster home]# ansible webservers:dbservers -m shell -a "echo "=======";hostname;echo "========";\n;ip a| grep ens34"
192.168.159.153 | CHANGED | rc=0 >>
=======
db1
========
3: ens34: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.159.153/24 brd 192.168.159.255 scope global ens34
    inet 192.168.159.156/24 brd 192.168.159.255 scope global secondary dynamic ens34/bin/sh: n: command not found

192.168.159.142 | CHANGED | rc=0 >>
=======
web1
========
3: ens34: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.159.142/24 brd 192.168.159.255 scope global ens34
    inet 192.168.159.155/24 brd 192.168.159.255 scope global secondary dynamic ens34/bin/sh: n: command not found

[root@ansimaster home]#



================= adhoc commands =======
[root@ansimaster ~]# ansible dbservers -m command -a /usr/bin/hostname
192.168.159.153 | CHANGED | rc=0 >>
db1

[root@ansimaster ~]# ansible webservers -m command -a /usr/bin/hostname
192.168.159.142 | CHANGED | rc=0 >>
web1

[root@ansimaster ~]# ansible localhost -m command -a /usr/bin/hostname
localhost | CHANGED | rc=0 >>
ansimaster

[root@ansimaster ~]#
======================================================================
Use -o optio to display ansible adhoc command outout in single line
======================================================================
[root@ansimaster ~]# ansible webservers -m command -a /usr/bin/hostname -o
192.168.159.142 | CHANGED | rc=0 | (stdout) web1
[root@ansimaster ~]#
[root@ansimaster ~]#
[root@ansimaster ~]# ansible dbservers -m command -a /usr/bin/hostname -o
192.168.159.153 | CHANGED | rc=0 | (stdout) db1
[root@ansimaster ~]#


[root@ansimaster ~]# ansible webservers -m command -a 'cat /etc/motd' -o
192.168.159.142 | CHANGED | rc=0 | (stdout) this is managed by ansible

[root@ansimaster ~]# ansible webservers -m copy -a 'content="etc/motd is managed by ansibale\n" dest=/etc/motd'  -o
192.168.159.142 | CHANGED => {"changed": true, "checksum": "d34ee6cd1004e828c6241cd9bb873555a6ac10c2", "dest": "/etc/motd", "gid": 0, "group": "root", "md5sum": "b0d0234efbedea7222af15bb134a40d4", "mode": "0644", "owner": "root", "secontext": "system_u:object_r:etc_t:s0", "size": 32, "src": "/root/.ansible/tmp/ansible-tmp-1562164775.78-137644172963725/source", "state": "file", "uid": 0}
[root@ansimaster ~]#
[root@ansimaster ~]# ansible dbservers -m copy -a 'content="etc/motd is managed by ansibale\n" dest=/etc/motd'  -o
192.168.159.153 | CHANGED => {"changed": true, "checksum": "d34ee6cd1004e828c6241cd9bb873555a6ac10c2", "dest": "/etc/motd", "gid": 0, "group": "root", "md5sum": "b0d0234efbedea7222af15bb134a40d4", "mode": "0644", "owner": "root", "secontext": "system_u:object_r:etc_t:s0", "size": 32, "src": "/root/.ansible/tmp/ansible-tmp-1562164789.3-108260834981552/source", "state": "file", "uid": 0}
[root@ansimaster ~]#
[root@ansimaster ~]# ansible webservers -m command -a 'cat /etc/motd' -o
192.168.159.142 | CHANGED | rc=0 | (stdout) etc/motd is managed by ansibale
[root@ansimaster ~]# ansible dbservers -m copy -a 'content="/etc/motd is managed by ansibale\n" dest=/etc/motd'  -o
192.168.159.153 | CHANGED => {"changed": true, "checksum": "95ab7b16d1a7d8dafbd55b57ffae5627d4b88b66", "dest": "/etc/motd", "gid": 0, "group": "root", "md5sum": "01f3b61cfe0086feca8a24208a7892b2", "mode": "0644", "owner": "root", "secontext": "system_u:object_r:etc_t:s0", "size": 33, "src": "/root/.ansible/tmp/ansible-tmp-1562164811.49-99926344171678/source", "state": "file", "uid": 0}
[root@ansimaster ~]#
[root@ansimaster ~]#
[root@ansimaster ~]# ansible webservers -m command -a 'cat /etc/motd' -o
192.168.159.142 | CHANGED | rc=0 | (stdout) etc/motd is managed by ansibale
[root@ansimaster ~]#
[root@ansimaster ~]#
[root@ansimaster ~]#

===================================================
Ad-hoc command to list httpd and firewalld installed on remote server

===================================================
root@ansimaster:/etc/ansible]#ansible webservers -a 'yum list installed firewalld'
 [WARNING]: Consider using yum module rather than running yum

192.168.122.50 | SUCCESS | rc=0 >>
Loaded plugins: fastestmirror, langpacks
Installed Packages
firewalld.noarch                        0.5.3-5.el7                        @base

[root@ansimaster:/etc/ansible]#

======================================================
ansible-doc is used to list available modules
======================================================
[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, vm...
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 assigned to pools (fvns:EncapBlk, fvns:VsanEncapBlk)
aci_epg                                              Manage End Point Groups (EPG) objects (fv:AEPg)
aci_epg_monitoring_policy                            Manage monitoring policies (mon:EPGPol)
aci_epg_to_contract                                  Bind EPGs to Contracts (fv:RsCons, fv:RsProv)
aci_epg_to_domain                                    Bind EPGs to Domains (fv:RsDomAtt)
aci_fabric_node                                      Manage Fabric Node Members (fabric:NodeIdentP)
aci_filter                                           Manages top level filter objects (vz:Filter)
aci_filter_entry                                     Manage filter entries (vz:Entry)
aci_firmware_source                                  Manage firmware image sources (firmware:OSource)
aci_interface_policy_fc                              Manage Fibre Channel interface policies (fc:IfPol)
aci_interface_policy_l2                              Manage Layer 2 interface policies (l2:IfPol)
aci_interface_policy_leaf_policy_group               Manage fabric interface policy leaf policy groups (infra:AccBndlGrp, infra:Acc...
aci_interface_policy_leaf_profile                    Manage fabric interface policy leaf profiles (infra:AccPortP)
aci_interface_policy_lldp                            Manage LLDP interface policies (lldp:IfPol)
aci_interface_policy_mcp                             Manage MCP interface policies (mcp:IfPol)
aci_interface_policy_ospf                            Manage OSPF interface policies (ospf:IfPol)
[root@ansimaster ~]#


[root@ansimaster ~]# ansible-doc yum
> YUM    (/usr/lib/python2.7/site-packages/ansible/modules/packaging/os/yum.py)

        Installs, upgrade, downgrades, removes, and lists packages and groups with the `yum' package
        manager. This module only works on Python 2. If you require Python 3 support see the [dnf] module.

  * note: This module has a corresponding action plugin.

OPTIONS (= is mandatory):

- allow_downgrade
        Specify if the named package and version is allowed to downgrade a maybe already installed higher
        version of that package. Note that setting allow_downgrade=True can make this module behave in a
        non-idempotent way. The task could end up with a set of packages that does not match the complete
        list of specified packages to install (because dependencies between the downgraded package and
        others can cause changes to the packages which were in the earlier transaction).
        [Default: no]
        type: bool
        version_added: 2.4

- autoremove
        If `yes', removes all "leaf" packages from the system that were originally installed as dependencies
        of user-installed packages but which are no longer required by any such package. Should be used
        alone or when state is `absent'
        NOTE: This feature requires yum >= 3.4.3 (RHEL/CentOS 7+)
        [Default: False]
        type: bool
        version_added: 2.7

------------- Snip --------------

------------- Snip --------------


EXAMPLES:

- name: install the latest version of Apache
  yum:
    name: httpd
    state: latest

- name: ensure a list of packages installed
  yum:
    name: "{{ packages }}"
  vars:
    packages:
    - httpd
    - httpd-tools

- name: remove the Apache package
  yum:
    name: httpd
    state: absent

- name: install the latest version of Apache from the testing repo
  yum:
    name: httpd
    enablerepo: testing
    state: present

- name: install one specific version of Apache
  yum:
    name: httpd-2.2.29-1.4.amzn1
  state: present

- name: upgrade all packages
  yum:
    name: '*'
    state: latest

- name: upgrade all packages, excluding kernel & foo related packages
  yum:
    name: '*'
    state: latest
    exclude: kernel*,foo*
- name: install the nginx rpm from a remote repo
  yum:
    name: http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
    state: present

- name: install nginx rpm from a local file
  yum:
    name: /usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm
    state: present

- name: install the 'Development tools' package group
  yum:
    name: "@Development tools"
    state: present

- name: install the 'Gnome desktop' environment group
  yum:
    name: "@^gnome-desktop-environment"
    state: present

- name: List ansible packages and register result to print with debug later.
  yum:
    list: ansible
  register: result
- name: Install package with multiple repos enabled
  yum:
    name: sos
    enablerepo: "epel,ol7_latest"

- name: Install package with multiple repos disabled
  yum:
    name: sos
    disablerepo: "epel,ol7_latest"

- name: Install a list of packages
  yum:
    name:
      - nginx
      - postgresql
      - postgresql-server
    state: present

- name: Download the nginx package but do not install it
  yum:
    name:
      - nginx
    state: latest
    download_only: true


==================================================================================
if we would like to list of procedure that a module can provide to use in playbook
Following is list of action we can add in playbook to execute using yum module
==================================================================================
   
    [root@ansimaster ~]# ansible-doc -s yum
- name: Manages packages with the `yum' package manager
  yum:
      allow_downgrade:       # Specify if the named package and version is allowed to downgrade a maybe already installed higher
                               version of that package. Note that setting allow_downgrade=True can make
                               this module behave in a non-idempotent way. The task could end up with a
                               set of packages that does not match the complete list of specified
                               packages to install (because dependencies between the downgraded package
                               and others can cause changes to the packages which were in the earlier
                               transaction).
      autoremove:            # If `yes', removes all "leaf" packages from the system that were originally installed as dependencies of
                               user-installed packages but which are no longer required by any such
                               package. Should be used alone or when state is `absent' NOTE: This
                               feature requires yum >= 3.4.3 (RHEL/CentOS 7+)
      bugfix:                # If set to `yes', and `state=latest' then only installs updates that have been marked bugfix related.
      conf_file:             # The remote yum configuration file to use for the transaction.
      disable_excludes:      # Disable the excludes defined in YUM config files. If set to `all', disables all excludes. If set to
                               `main', disable excludes defined in [main] in yum.conf. If set to
                               `repoid', disable excludes defined for given repo id.
      disable_gpg_check:     # Whether to disable the GPG checking of signatures of packages being installed. Has an effect only if
                               state is `present' or `latest'.
      disable_plugin:        # `Plugin' name to disable for the install/update operation. The disabled plugins will not persist beyond
                               the transaction.
      disablerepo:           # `Repoid' of repositories to disable for the install/update operation. These repos will not persist
                               beyond the transaction. When specifying multiple repos, separate them
                               with a `","'. As of Ansible 2.7, this can alternatively be a list instead
                               of `","' separated string
      download_only:         # Only download the packages, do not install them.
      enable_plugin:         # `Plugin' name to enable for the install/update operation. The enabled plugin will not persist beyond the
                               transaction.
      enablerepo:            # `Repoid' of repositories to enable for the install/update operation. These repos will not persist beyond
                               the transaction. When specifying multiple repos, separate them with a
                               `","'. As of Ansible 2.7, this can alternatively be a list instead of
                               `","' separated string
      exclude:               # Package name(s) to exclude when state=present, or latest
      installroot:           # Specifies an alternative installroot, relative to which all packages will be installed.
      list:                  # Package name to run the equivalent of yum list <package> against. In addition to listing packages, use
                               can also list the following: `installed', `updates', `available' and
                               `repos'.
      name:                  # A package name or package specifier with version, like `name-1.0'. If a previous version is specified,
                               the task also needs to turn `allow_downgrade' on. See the
                               `allow_downgrade' documentation for caveats with downgrading packages.
                               When using state=latest, this can be `'*'' which means run `yum -y
                               update'. You can also pass a url or a local path to a rpm file (using
                               state=present). To operate on several packages this can accept a comma
                               separated string of packages or (as of 2.0) a list of packages.
      releasever:            # Specifies an alternative release from which all packages will be installed.
      security:              # If set to `yes', and `state=latest' then only installs updates that have been marked security related.
      skip_broken:           # Skip packages with broken dependencies(devsolve) and are causing problems.
      state:                 # Whether to install (`present' or `installed', `latest'), or remove (`absent' or `removed') a package.
                               `present' and `installed' will simply ensure that a desired package is
                               installed. `latest' will update the specified package if it's not of the
                               latest available version. `absent' and `removed' will remove the
                               specified package. Default is `None', however in effect the default
                               action is `present' unless the `autoremove' option is¬ enabled for this
                               module, then `absent' is inferred.
      update_cache:          # Force yum to check if cache is out of date and redownload if needed. Has an effect only if state is
                               `present' or `latest'.
[root@ansimaster ~]#


[root@ansimaster ~]# ansible webservers -m service -a "name=httpd state=restarted"
192.168.159.142 | CHANGED => {
    "changed": true,
    "name": "httpd",
    "state": "started",
    "status": {
        "ActiveEnterTimestampMonotonic": "0",
        "ActiveExitTimestampMonotonic": "0",
        "ActiveState": "inactive",
        "After": "nss-lookup.target -.mount basic.target network.target systemd-journald.socket remote-fs.target system.slice tmp.mount",
        "AllowIsolate": "no",
        "AssertResult": "no",
        "AssertTimestampMonotonic": "0",

        ---------- Snip------------
        ---------- Snip------------
       
       
       
        [root@web1 ~]# systemctl satus httpd
Unknown operation 'satus'.

========status before run adhoc command on master server ======


[root@web1 ~]# 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)
[root@web1 ~]#


========status after run adhoc command on master server ======


[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 Thu 2019-07-04 07:16:19 EDT; 6s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 12286 (httpd)
   Status: "Processing requests..."
   CGroup: /system.slice/httpd.service
           ├─12286 /usr/sbin/httpd -DFOREGROUND
           ├─12287 /usr/sbin/httpd -DFOREGROUND
           ├─12288 /usr/sbin/httpd -DFOREGROUND
           ├─12289 /usr/sbin/httpd -DFOREGROUND
           ├─12290 /usr/sbin/httpd -DFOREGROUND
           └─12291 /usr/sbin/httpd -DFOREGROUND

Jul 04 07:16:19 web1 systemd[1]: Starting The Apache HTTP Server...
Jul 04 07:16:19 web1 httpd[12286]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, usi... message
Jul 04 07:16:19 web1 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.


==================================================================
executing playbook interactively
==================================================================
[root@ansimaster playbooks]# ansible-playbook --step apache_playbook2.yml -v
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] **********************************************************************************************************************
Perform task: TASK: Gathering Facts (N)o/(y)es/(c)ontinue: y

Perform task: TASK: Gathering Facts (N)o/(y)es/(c)ontinue: *****************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************
ok: [192.168.159.142]
Perform task: TASK: Install httpd package (N)o/(y)es/(c)ontinue: y

Perform task: TASK: Install httpd package (N)o/(y)es/(c)ontinue: ***********************************************************************

TASK [Install httpd package] ***********************************************************************************************************
ok: [192.168.159.142] => {"changed": false, "msg": "", "rc": 0, "results": ["httpd-2.4.6-89.el7.centos.x86_64 providing httpd is already installed"]}
Perform task: TASK: Start appache services (N)o/(y)es/(c)ontinue: y

Perform task: TASK: Start appache services (N)o/(y)es/(c)ontinue: **********************************************************************

TASK [Start appache services] **********************************************************************************************************
ok: [192.168.159.142] => {"changed": false, "name": "httpd", "state": "started", "status": {"ActiveEnterTimestamp": "Fri 2019-07-05 07:17:41 EDT", "ActiveEnterTimestampMonotonic": "1625

<======= output snip ======>
<======= output snip ======>

Perform task: TASK: Deploying httpd conf (N)o/(y)es/(c)ontinue: y

Perform task: TASK: Deploying httpd conf (N)o/(y)es/(c)ontinue: ************************************************************************

TASK [Deploying httpd conf] ************************************************************************************************************
ok: [192.168.159.142] => {"changed": false, "dest": "/usr/share/httpd/noindex/", "src": "/ansible/config/httpd/conf/"}

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

[root@ansimaster playbooks]#

Monday, June 24, 2019

How to configure network bonding in linux

How to configure network bonding in linux

 We will configure active-backup bonding
 Then will do testing, just to disable one interface and check. we should be able to access our  machine using the bond ip.


[root@server ~]# vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
IPADDR=192.168.159.164
NETMASK=255.255.255.0
GATEWAY=192.168.5.1
USERCTL=no
BOOTPROTO=static
ONBOOT=yes
BONDING_OPTS="mode=1 miimon=100"

[root@server ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
[root@server ~]#
[root@server ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none

[root@server ~]# vi /etc/modprobe.conf
alias bond0 bonding
[root@server ~]#

[root@server ~]# modprobe bonding


[root@server ~]# /etc/init.d/network restart
Shutting down interface bond0:                             [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface bond0:                               [  OK  ]
[root@server ~]#


[root@server ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up            <============== Showing status up eth0
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 00:0c:29:16:ad:b4
Slave queue ID: 0

Slave Interface: eth1
MII Status: up        <============== Show status up for eth1
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 00:0c:29:16:ad:be
Slave queue ID: 0
[root@server ~]#



[root@server ~]# ethtool eth0
Settings for eth0:
        Current message level: 0x00000007 (7)
        Link detected: yes
[root@server ~]# ethtool eth1
Settings for eth1:
        Current message level: 0x00000007 (7)
        Link detected: yes
[root@server ~]#


===============================================================================
Now we do some testing by disabling link for eth 1 and then check bond0 status
===============================================================================

[root@server ~]# grep link /var/log/messages
Jun 22 18:29:59 server kernel: eth1: link down
Jun 22 18:29:59 server kernel: bonding: bond0: link status definitely down for interface eth1, disabling it

[root@server ~]#
[root@server ~]#


[root@server ~]# ethtool eth1
Settings for eth1:
        Current message level: 0x00000007 (7)
        Link detected: no
[root@server ~]#


[root@server ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0 <======== show link status up for eth0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 00:0c:29:16:ad:b4
Slave queue ID: 0

Slave Interface: eth1
MII Status: down    <======== show link status down for eth1, and we still connected to our machine
Speed: Unknown                  hence we confirm bonding is working well
Duplex: Unknown
Link Failure Count: 1
Permanent HW addr: 00:0c:29:16:ad:be
Slave queue ID: 0

[root@server ~]#
[root@server ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UNKNOWN qlen 1000
    link/ether 00:0c:29:16:ad:b4 brd ff:ff:ff:ff:ff:ff
3: eth1: <NO-CARRIER,BROADCAST,MULTICAST,SLAVE,UP> mtu 1500 qdisc pfifo_fast master bond0 state DOWN qlen 1000 
    link/ether 00:0c:29:16:ad:b4 brd ff:ff:ff:ff:ff:ff
4: pan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN
    link/ether e6:79:4f:de:c4:c1 brd ff:ff:ff:ff:ff:ff
5: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
    link/ether 00:0c:29:16:ad:b4 brd ff:ff:ff:ff:ff:ff
    inet 192.168.159.164/24 brd 192.168.159.255 scope global bond0
    inet6 fe80::20c:29ff:fe16:adb4/64 scope link
       valid_lft forever preferred_lft forever

=====================================================================================================================      
Note: output of eth1 output there is LOWER_UP, flag is missing which we will match again once eth1 network recoverd
=====================================================================================================================


=========================================================
check bond0 status after connection recoverd for eth1
=========================================================

[root@server ~]# grep link /var/log/messages
Jun 22 18:32:15 server kernel: eth1: link up
Jun 22 18:32:15 server kernel: bond0: link status definitely up for interface eth1, 4294967295 Mbps full duplex.

[root@server ~]# cat /proc/net/bonding/bond0

Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 00:0c:29:16:ad:b4
Slave queue ID: 0

Slave Interface: eth1
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 1
Permanent HW addr: 00:0c:29:16:ad:be
Slave queue ID: 0
[root@server ~]# ethtool eth1
Settings for eth1:
        Current message level: 0x00000007 (7)
        Link detected: yes
[root@server ~]#

=====================================================================================================================
Note: output of eth1 output there is LOWER_UP, flag is back which we will match again once eth1 network recoverd
=====================================================================================================================
[root@server ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UNKNOWN qlen 1000
    link/ether 00:0c:29:16:ad:b4 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000
    link/ether 00:0c:29:16:ad:b4 brd ff:ff:ff:ff:ff:ff
4: pan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN
    link/ether e6:79:4f:de:c4:c1 brd ff:ff:ff:ff:ff:ff
5: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
    link/ether 00:0c:29:16:ad:b4 brd ff:ff:ff:ff:ff:ff
    inet 192.168.159.164/24 brd 192.168.159.255 scope global bond0
    inet6 fe80::20c:29ff:fe16:adb4/64 scope link
       valid_lft forever preferred_lft forever
[root@server ~]#







=========================================================
Different Modes that can be used in /etc/modprobe.conf
=========================================================
    balance-rr or 0 — round-robin mode for fault tolerance and load balancing.
    active-backup or 1 — Sets active-backup mode for fault tolerance.
    balance-xor or 2 — Sets an XOR (exclusive-or) mode for fault tolerance and load balancing.
    broadcast or 3 — Sets a broadcast mode for fault tolerance. All transmissions are sent on all slave interfaces.
    802.3ad or 4 — Sets an IEEE 802.3ad dynamic link aggregation mode. Creates aggregation groups that share the same speed & duplex settings.
    balance-tlb or 5 — Sets a Transmit Load Balancing (TLB) mode for fault tolerance & load balancing.
    balance-alb or 6 — Sets an Active Load Balancing (ALB) mode for fault tolerance & load balancing.

=====================================================
    #Now following is explanation about LOWER_UP:
=====================================================   
LOWER_UP is a physical layer link flag (the layer below the network layer, where IP is generally located).
LOWER_UP indicates that an Ethernet cable is plugged in device is connected to the network.

LOWER_UP differs from UP, which additionally requires the network interface to be enabled.

Saturday, June 22, 2019

Configure Multipath in linux

[root@server scsi_host]# iscsiadm -m discovery -t st -p  192.168.150.1
Starting iscsid:                                           [  OK  ]
192.168.150.1:3260,-1 iqn.2008-08.com.starwindsoftware:192.168.150.1-linuxstoragepool
[root@server scsi_host]# iscsiadm -m discovery -t st -p  192.168.150.1,3260
192.168.150.1:3260,-1 iqn.2008-08.com.starwindsoftware:192.168.150.1-linuxstoragepool
[root@server scsi_host]# iscsiadm -m node -L all
Logging in to [iface: default, target: iqn.2008-08.com.starwindsoftware:192.168.150.1-linuxstoragepool, portal: 192.168.150.1,3260] (multiple)
Login to [iface: default, target: iqn.2008-08.com.starwindsoftware:192.168.150.1-linuxstoragepool, portal: 192.168.150.1,3260] successful.

[root@server scsi_host]# multipath -ll
mpatha (2628fb3127e8f77f6) dm-3 ROCKET,IMAGEFILE
size=5.0G features='0' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=1 status=active
  `- 3:0:0:0 sde 8:64 active ready running

 
 =================================================================
  Now configure 2nd network path for storage disks.
 =================================================================
[root@server scsi_host]#  iscsiadm -m discovery -t st -p  192.168.159.1
192.168.159.1:3260,-1 iqn.2008-08.com.starwindsoftware:192.168.150.1-linuxstoragepool
192.168.159.1:3260,-1 iqn.2008-08.com.starwindsoftware:192.168.159.1-linuxstoragepool
[root@server scsi_host]#  iscsiadm -m discovery -t st -p  192.168.159.1,3260
192.168.159.1:3260,-1 iqn.2008-08.com.starwindsoftware:192.168.150.1-linuxstoragepool
192.168.159.1:3260,-1 iqn.2008-08.com.starwindsoftware:192.168.159.1-linuxstoragepool


[root@server multipath]#  iscsiadm -m node -L all
Logging in to [iface: default, target: iqn.2008-08.com.starwindsoftware:192.168.159.1-linuxstoragepool, portal: 192.168.159.1,3260] (multiple)
Logging in to [iface: default, target: iqn.2008-08.com.starwindsoftware:192.168.150.1-linuxstoragepool, portal: 192.168.159.1,3260] (multiple)
Login to [iface: default, target: iqn.2008-08.com.starwindsoftware:192.168.159.1-linuxstoragepool, portal: 192.168.159.1,3260] successful.
Login to [iface: default, target: iqn.2008-08.com.starwindsoftware:192.168.150.1-linuxstoragepool, portal: 192.168.159.1,3260] successful.

==============================================================
Now in following output you can see boths disks are showing 2 paths for eachs disk
==============================================================
[root@server multipath]# multipath -ll
mpathb (26eb538fc86227b31) dm-4 ROCKET,IMAGEFILE
size=50G features='0' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=1 status=enabled
| `- 3:0:0:1 sdf 8:80  active ready running
`-+- policy='round-robin 0' prio=1 status=active
  `- 5:0:0:1 sdh 8:112 active ready running
mpatha (2628fb3127e8f77f6) dm-3 ROCKET,IMAGEFILE
size=5.0G features='0' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=1 status=enabled
| `- 3:0:0:0 sde 8:64  active ready running
`-+- policy='round-robin 0' prio=1 status=active
  `- 5:0:0:0 sdg 8:96  active ready running
[root@server multipath]#
[root@server multipath]#
[root@server multipath]#

====================================================================
Now lets try to disable one path and we should see active faulty running in multipath -ll output
====================================================================
 [root@server ~]# multipath -ll

mpathb (26eb538fc86227b31) dm-4 ROCKET,IMAGEFILE
size=50G features='0' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=0 status=enabled
| `- 3:0:0:1 sdf 8:80  active faulty running      <============ See we have one path faulty for  mpathb disk
`-+- policy='round-robin 0' prio=1 status=active
  `- 5:0:0:1 sdh 8:112 active ready running
mpatha (2628fb3127e8f77f6) dm-3 ROCKET,IMAGEFILE
size=5.0G features='0' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=0 status=enabled
| `- 3:0:0:0 sde 8:64  active faulty running
`-+- policy='round-robin 0' prio=1 status=active
  `- 5:0:0:0 sdg 8:96  active ready running

 ============================ ===========================
Now enable vmnet virtaul adapter and path should be recover by its own
=========================== ============================  
  [root@server ~]# multipath -ll
mpathb (26eb538fc86227b31) dm-4 ROCKET,IMAGEFILE
size=50G features='0' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=1 status=enabled
| `- 3:0:0:1 sdf 8:80  active ready running
`-+- policy='round-robin 0' prio=1 status=active
  `- 5:0:0:1 sdh 8:112 active ready running
mpatha (2628fb3127e8f77f6) dm-3 ROCKET,IMAGEFILE
size=5.0G features='0' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=1 status=enabled
| `- 3:0:0:0 sde 8:64  active ready running
`-+- policy='round-robin 0' prio=1 status=active
  `- 5:0:0:0 sdg 8:96  active ready running

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
=============================================================================


kubernetes Pod Scheduling

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