• Ansible - device configs comparison

    This Article will contain Ansible playbook example for Device configuration comparison.

    Prerequsites (assumptions):

    - Ansible installed on Linux
    - Devise Configuration happaning daily and stored in /home/administrator/network-programmability/backups/SWITCH/

    Ansible notes will be posted here and continuesly updated on the fly when required.

    Ansible environment as always devided for 2 servers: PRODuction and DEVelopment.
    Tested scrypts will be moved from DEV into PROD server once fully tested and ready.


    Manual execution (for test):

    ansible-playbook diff.yml

     

    Output files location:

    ls home/administrator/network-programmability/
     

    Scheduling done over crontub:

    # Execute against config DIFF
    5 6 * * * if ! out=`ansible-playbook /etc/ansible/diff.yml`; then echo $out; fi

     

    Playbook:

    --
    ## Playbook to get system time and append it to backup files ## Made by DM ## Last change 09/06/2021 - hosts: localhost tasks: - name: Get ansible date/time facts setup: filter: "ansible_date_time" gather_subset: "!all" - name: Store DTG as fact set_fact: DTG: "{{ ansible_date_time.date }}" DTGY: "{{ '%Y-%m-%d'|strftime(ansible_date_time.epoch|int - 86400*1) }}" - hosts: SWITCH connection: network_cli gather_facts: no tasks: - name: DIFF shell: "diff /home/administrator/network-programmability/backups/SWITCH/{{hostvars.localhost.DTGY}}/{{inventory_hostname}}-{{hostvars.localhost.DTGY}}-config.txt /home/administrator/network-programmability/backups/SWITCH/{{hostvars.localhost.DTG}}/{{inventory_hostname}}-{{hostvars.localhost.DTG}}-config.txt " register: diff_output failed_when: diff_output.rc >= 2 delegate_to: localhost - name: COPY copy: content: "{{ diff_output.stdout }}" dest: "/home/administrator/network-programmability/backups/SWITCH/DIFF/{{inventory_hostname}}-{{hostvars.localhost.DTGY}}-{{hostvars.localhost.DTG}}.txt" when: diff_output.rc == 1 failed_when: diff_output.rc >= 2 delegate_to: localhost - name: Send a success email mail: host: smtp.mydomain.com.au port: 25 from: This email address is being protected from spambots. You need JavaScript enabled to view it. (Ansible Automation) to: - USER01 <This email address is being protected from spambots. You need JavaScript enabled to view it.> - USER02 <This email address is being protected from spambots. You need JavaScript enabled to view it.> subject: "Compare {{ inventory_hostname }} config {{ hostvars.localhost.DTG }} against {{ hostvars.localhost.DTGY }}" body: "This email include changes for {{inventory_hostname}} compare to config day before. \n {{ diff_output.stdout }} \n \n DO NOT REPLY TO THIS EMAIL" attach: "/home/administrator/network-programmability/backups/SWITCH/DIFF/{{inventory_hostname}}-{{hostvars.localhost.DTGY}}-{{hostvars.localhost.DTG}}.txt" when: diff_output.rc == 1 failed_when: diff_output.rc >= 2 delegate_to: localhost
  • Ansible - automation against HP Aruba OS CX Switch

    This Article will contain Ansible playbook setup example against Dell Switches.

    Ansible notes will be posted here and continuesly updated on the fly when required.

    Ansible environment as always devided for 2 servers: PRODuction and DEVelopment.
    Tested scrypts will be moved from DEV into PROD server once fully tested and ready.

    Aruba OSCX playbooks required additional roles installed

    Next CLI command will be applied to both servers:
    ansible-galaxy install arubanetworks.aoscx_role
    ansible-galaxy collection install ansible.netcommon
     
    Also, changes to the ansible.conf:
    host_key_auto_add = True

     

    Host file content:

    Ansible configuration files location: /etc/ansible

    [AOSCX]
    AOSCX01 ansible_host=10.x.x.x1
    AOSCX01 ansible_host=10.x.x.x2


    [AOSCX:vars]

    ansible_user=admin
    ansible_ssh_pass=****

    Manual execution (for test):

    ansible-playbook aoscx.yml

     

    Output files location:

    ls home/administrator/network-programmability/
     

    Scheduling done over crontub:

    # Execute against Aruba OS CX switches
    5 6 * * * if ! out=`ansible-playbook /etc/ansible/aoscx.yml`; then echo $out; fi

     

    Playbook:

    ---
    ## Playbook to get system time and append it to backup files for Aruba OS CX
    ## Made by DM
    ## Last change 09/06/2021
    
    - hosts: localhost
      tasks:
       - name: Get ansible date/time facts
         setup:
           filter: "ansible_date_time"
           gather_subset: "!all"
    
       - name: Store DTG as fact
         set_fact:
           DTG: "{{ ansible_date_time.date }}"
    
       - name: Create Directory {{hostvars.localhost.DTG}}
         file:
          path: ~/network-programmability/backups/AOSCX/{{hostvars.localhost.DTG}}
          state: directory
      run_once: true
    
    - hosts: AOSCX
      roles: 
        - role: arubanetworks.aoscx_role
      vars:
        ansible_connection: network_cli
      tasks:
        - name: Execute show run on the switch
          aoscx_command:
            commands: ['show run']
          register: config
        - name: Save output to ~/network-programmability/backups/AOSCX
          copy:
            content: "{{config.stdout[0]}}"
            dest: "/home/administrator/network-programmability/backups/AOSCX/{{hostvars.localhost.DTG}}/{{inventory_hostname}}-{{hostvars.localhost.DTG}}-config.txt" 

  • Ansible - automation against Dell Switch

    This Article will contain Ansible playbook setup example against Dell Switches.

    Ansible notes will be posted here and continuesly updated on the fly when required.

    Ansible environment as always devided for 2 servers: PRODuction and DEVelopment.
    Tested scrypts will be moved from DEV into PROD server once fully tested and ready.

    Host file content:

    Ansible configuration files location: /etc/ansible

    [DellL]
    DellL01 ansible_host=10.x.x.x1
    DellL02 ansible_host=10.x.x.x2


    [DellL:vars]

    ansible_user=admin
    ansible_ssh_pass=****
    [DellS]
    DellS01 ansible_host=10.x.x.x1
    DellS02 ansible_host=10.x.x.x2

    [DellS:vars]
    ansible_user=admin
    ansible_ssh_pass=****

     

    Manual execution (for test):

    ansible-playbook os9backup.yml

     

    Output files location:

    ls home/administrator/network-programmability/
     

    Scheduling done over crontub:

    # Execute against Dell switches
    5 6 * * * if ! out=`ansible-playbook /etc/ansible/os9backup.yml`; then echo $out; fi

     

    Playbook:

    ---
    ## Playbook to get system time and append it to backup files
    ## Made by DM
    ## Last change 09/06/2021
    
    - hosts: localhost
    
      tasks:
       - name: Get ansible date/time facts
         setup:
           filter: "ansible_date_time"
           gather_subset: "!all"
    
       - name: Store DTG as fact
         set_fact:
           DTG: "{{ ansible_date_time.date }}"
    
       - name: Create Directory {{hostvars.localhost.DTG}}
         file:
          path: ~/network-programmability/backups/DELL/{{hostvars.localhost.DTG}}
          state: directory
      run_once: true
    
    - hosts: DellL
      connection: network_cli
      gather_facts: no
    
      tasks:
      - name: Backup Dell Leaf current switch config
        dellos9_config:
          backup: yes
          backup_options:
            dir_path: /home/administrator/network-programmability/backups/DELL/{{hostvars.localhost.DTG}}/
    
    - hosts: DellS
      connection: network_cli
      gather_facts: no
    
      vars:
        command_list:
          - show ip interface brief
          - show arp
          - show vrrp brief
          - show interface status
          - show logging 50
    
      tasks:
      - name: Backup Dell Spine current switch config
        dellos9_config:
          backup: yes
          backup_options:
            dir_path: /home/administrator/network-programmability/backups/DELL/{{hostvars.localhost.DTG}}/
    
      - name: Get Dell EMC OS9 Show commands
        dellos9_command:
           commands: "{{ command_list }}"
        register: showoutput
    
      - name: Save output to /home/administrator/network-programmability/backups/DELL
        template:
          src: template.j2
          dest: "/home/administrator/network-programmability/backups/DELL/{{hostvars.localhost.DTG}}/{{inventory_hostname}}-{{hostvars.localhost.DTG}}-show.txt"

    template.j2

    OUTPUT FROM SHOW COMMANDS for: {{ inventory_hostname }}
    {% for cmd in command_list %}
    ############ {{ cmd }} ################ {{ showoutput.stdout[loop.index0] }} {% endfor %}
  • Ansible - automation against Cisco Router

    This Article will contain Ansible playbook setup example against Cisco Routers.

    Ansible notes will be posted here and continuesly updated on the fly when required.

    Ansible environment as always devided for 2 servers: PRODuction and DEVelopment.
    Tested scrypts will be moved from DEV into PROD server once fully tested and ready.

    Host file content:

    Ansible configuration files location: etc/ansible

    [CiscoASR]
    ASR01 ansible_host=10.x.x.x1
    ASR02 ansible_host=10.x.x.x2

    ASR03 ansible_host=10.x.x.x3
    ASR04 ansible_host=10.x.x.x4
    [CiscoASR:vars]
    ansible_user=admin
    ansible_ssh_pass=****

     

    Manual execution (for test):

    ansible-playbook ciscobackup.yml

     

    Output files location:

    ls home/administrator/network-programmability/
     

    Scheduling done over crontub:

    crontab -e
    0 1 * * * if ! out=`ansible-playbook etc/ansible/cisco.yml`; then echo $out; fi

     

    Playbook:

    ---
    ## Playbook to get system time and append it to backup files
    ## Made by DM
    ## Last change 09/06/2021
    
    - hosts: localhost
    
      tasks:
       - name: Get ansible date/time facts
         setup:
           filter: "ansible_date_time"
           gather_subset: "!all"
    
       - name: Store DTG as fact
         set_fact:
           DTG: "{{ ansible_date_time.date }}"
    
       - name: Create Directory {{hostvars.localhost.DTG}}
         file:
          path: ~/network-programmability/backups/ASR/{{hostvars.localhost.DTG}}
          state: directory
      run_once: true
    
    
    - hosts: CiscoASR
      gather_facts: false
      connection: local
    
      tasks:
       - name: Show IP int brief 
         ios_command:
           commands: show ip int brief  
         register: config
    
       - name: Save output to /home/administrator/network-programmability/backups/ASR/
         copy:
           content: "{{config.stdout[0]}}"
           dest: "/home/administrator/network-programmability/backups/ASR/{{hostvars.localhost.DTG}}/{{inventory_hostname}}-{{hostvars.localhost.DTG}}-showipint.txt"
    
    
    - hosts: CiscoASR
      gather_facts: false
      connection: network_cli
    
      tasks:
       - name: Backup Config
         ios_config:
           backup: yes
           backup_options:
             filename: "{{inventory_hostname}}-{{hostvars.localhost.DTG}}-config.txt"
             dir_path: /home/administrator/network-programmability/backups/ASR/{{hostvars.localhost.DTG}}
         become: yes
         become_method: enable
    
       - name: Show History All
         ios_command:
           commands: show history all
         register: shhistall
         become: yes
         become_method: enable
    
       - name: Save output to /home/administrator/network-programmability/backups/ASR/
         copy:
           content: "{{shhistall.stdout[0]}}"
           dest: "/home/administrator/network-programmability/backups/ASR/{{hostvars.localhost.DTG}}/{{inventory_hostname}}-{{hostvars.localhost.DTG}}-showhistall.txt"
    
    - hosts: CiscoASR
      gather_facts: false
      connection: local
    
      vars:
        command_list:
         - show clock
         - sh ip ospf neighbor
    
      tasks:
       - name: Run the SHOW commands and save output 
         ios_command:
           commands: "{{ command_list }}"
         register: showoutput
    
       - name: "Put all the files together into one nice text file"
         template: 
           src: template.j2 
           dest: "/home/administrator/network-programmability/backups/ASR/{{hostvars.localhost.DTG}}/{{ inventory_hostname }}-{{hostvars.localhost.DTG}}-showoutput.txt"
     
    

    template.j2

    OUTPUT FROM SHOW COMMANDS for: {{ inventory_hostname }}
    {% for cmd in command_list %}
    ############ {{ cmd }} ################ {{ showoutput.stdout[loop.index0] }} {% endfor %}
  • CentOS - extend volume on VM

    How to resize a VMWARE virtual disk and Resize LVM on CentOS.

    *WARNING* THIS CAN RESULT IN FILE SYSTEM CORRUPTION IF DONE IMPROPERLY.
    Backup SERVER is *STRONGLY* recommended.


    First just check the partition table of the virtual disk in the VM

    # fdisk -l /dev/sda

    Disk /dev/sda: 68.7 GB, 68719476736 bytes
    255 heads, 63 sectors/track, 10443 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot Start End Blocks Id System
    /dev/sda1 * 1 13 104391 83 Linux
    /dev/sda2 14 8354 66999082+ 8e Linux LVM

    Now, shutdown the guest in preparation to resize the virtual disk

    # shutdown

    Resize the guest OS partition using VSphere Client (ESXi) or other VMtool (See VMWare support)

    Boot the AirWave VM guest back up, and add a new partition with the free space of the virtual disk. Make sure to use partition id 8e for Linux LVM.

    # fdisk /dev/sda
    # n {new partition}
    # p {primary partition}
    # 3 {select partition number, by default 3 is the next available}

    # t {select partition id we just made (3)}
    # 8e {Linux LVM partition}
    # p {print. the new device should be described as Linux LVM}
    # w {write to memory}

    You will need to reboot if fdisk updated kernel tables, just follow the recommendation message that will show up.

    # reboot

    You can check the partition table after the reboot if you like, make sure it looks like what you expect

    fdisk -l /dev/sda

    Disk /dev/sda: 85.8 GB, 85899345920 bytes
    255 heads, 63 sectors/track, 10443 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot Start End Blocks Id System
    /dev/sda1 * 1 13 104391 83 Linux
    /dev/sda2 14 8354 66999082+ 8e Linux LVM
    /dev/sda3 8355 10443 16779892+ 8e Linux LVM
    Now, create a new physical volume from the new partition

    # pvcreate /dev/sda3

    Then extend the existing volume group, you may want to use vgdisplay to list and identify the volume groups you have.

    # vgextend VolGroup00 /dev/sda3

    Now, extend the logical volume, again, use lvdisplay to list and identify the logical volumes you have.

    # lvextend -L<TOTAL_VOLUME_DESIRED_SIZE>G /dev/VolGroup00/LogVol00 /dev/sda3
    And finally, resize the filesystem in the logical volume

    # resize2fs /dev/VolGroup00/LogVol00

    Done.

  • CentOS - add HDD on VM

    How to add a VMWARE virtual disk on CentOS.

    *WARNING* THIS CAN RESULT IN FILE SYSTEM CORRUPTION IF DONE IMPROPERLY.
    Backup SERVER is *STRONGLY* recommended.


    First just check the partition table of the virtual disk in the VM

    # fdisk -l

    Now, shutdown the guest in preparation to add the additional virtual disk

    # shutdown

    Check system again

    # fdisk -l

    # fdisk /dev/sdb
    # n {new partition}
    # p {primary partition}
    # 1 {select partition number, by default 1 is the next available}

    # t {select partition id we just made (1)}
    # p {print. the new device should be described as Linux LVM}
    # w {write to memory}

    You will need to reboot if fdisk updated kernel tables, just follow the recommendation message that will show up.

    # reboot

    You can check the partition table after the reboot if you like, make sure it looks like what you expect

    fdisk -l /dev/sdb

    Disk /dev/sdb: 85.8 GB, 85899345920 bytes

    Now, create a new physical volume from the new partition

    # pvcreate /dev/sdb1

    # mkdir /mnt/cache

    Then (I prefer XFS system, you also can use ext4)

    # /sbin/mkfs.xfs -L /mnt/cache /dev/sdb1

    Configuring CentOS 6 to Automatically Mount a File System

    In order to set up the system so that the new file system is automatically mounted at boot time an entry needs to be added to the /etc/fstab file.

    /dev/sdb1    /mnt/cache   xfs    defaults        1 2

    Done.

  • CentOS notes

    Assign IP address:

    ifconfig -a
    # vi /etc/sysconfig/network-scripts/ifcfg-eth0

    DEVICE=eth0
    IPADDR=192.168.0.2
    NETMASK=255.255.255.0
    GATEWAY=192.168.0.254

    # service network restart

    Now you able to access via SSH:

    Add rest of config to

    DEVICE=eth0
    BOOTPRO=none
    IPV6INIT=no
    NM_CONTROLLED=no
    ONBOOT=yes
    TYPE=Ethernet
    USERCTL=no
    PEERDNS=yes
    DNS1=8.8.8.8
    DNS2=8.8.4.4
    DOMAIN=domain.local

    -= YUM =-

    yum update
    yum clean all

    Change Tomezone:
    cp /usr/share/zoneinfo/Australia/Melbourne /etc/localtime

  • Update Ubuntu Linux Softwares

    When you logged in to ubuntu Linux ssh concole you getting:
    25 packages can be updated.
    60 updates are security updates.

    Ubuntu Linux can be upgraded using GUI tools or using traditional command line tools such as: 

    1. apt-get command - apt-get is the command-line tool for handling packages.
    2. aptitude command - aptitude is a text-based interface to the Debian GNU/Linux package system including Ubuntu Linux

    I prefer to install updates via apt-get command line:

    1. gpt-get update : Update is used to resynchronize the package index files from their sources via Internet.
    2. apt-get upgrade : Upgrade is used to install the newest versions of all packages currently installed on the system
    3. apt-get dist-upgrade : Install kernel updates on a Ubuntu LTS server
    4. reboot

    For Server Version upgrade from LTS to LTS:

    sudo do-release-upgrade
    

    NOTE: Please always make sure you test the target LTS you're being prompted to upgrade to in a LiveCD on the machine you're using to make sure everything works properly before going in for the real upgrade itself.

  • Ubintu: reset root password

    Boot up the machine, and after the BIOS screen, hold down the left Shift key. You will then be prompted by a menu. (Sometimes you have to choose ADVANCED mode)

    From next menu select the one with the recovery mode in the description

    From Recovery Menu choose Root - Grop a root shell menu

    You should now see a root prompt, something like this:

    root@ubuntu:~#
    

    At this stage you should have a read-only filesystem. You have to remount it with write permissions:

    mount -rw -o remount /
    

    Now we can set the user's password with the passwd command. (In this example I will use jorge as the example, you need to substitute whatever the user's username is):

    root@ubuntu:~# passwd jorge
    Enter new UNIX password:
    Retype new UNIX password:
    passwd: password updated successfully
    root@ubuntu:~#
    
  • SELinux - disable security

    From the command line, you can edit the /etc/sysconfig/selinux file. This file is a symlink to /etc/selinux/config. The configuration file is self-explanatory. Changing the value of SELINUX or SELINUXTYPE changes the state of SELinux and the name of the policy to be used the next time the system boots.

    [root@host2a ~]# cat /etc/sysconfig/selinux
    # This file controls the state of SELinux on the system.
    # SELINUX= can take one of these three values:
    #       enforcing - SELinux security policy is enforced.
    #       permissive - SELinux prints warnings instead of enforcing.
    #       disabled - SELinux is fully disabled.
    SELINUX=permissive
    # SELINUXTYPE= type of policy in use. Possible values are:
    #       targeted - Only targeted network daemons are protected.
    #       strict - Full SELinux protection.
    SELINUXTYPE=targeted
    
    # SETLOCALDEFS= Check local definition changes
    SETLOCALDEFS=0
    
  • Squid just as home cache proxy

    Set the default value for max-size parameter on any cache_dir.
    The value is specified in bytes, and the default is 4 MB.

    If you wish to get a high BYTES hit ratio, you should probably
    increase this (one 32 MB object hit counts for 3200 10KB
    hits).

     maximum_object_size 10240 KB

     

    To verify your configuration file you can use the -k parse option

    % /usr/local/squid/sbin/squid -k parse

     

    How can I disable Squid's log files?

    To disable access.log:

            cache_access_log /dev/null
    

    To disable store.log:

            cache_store_log none
    

    It is a bad idea to disable the cache.log because this file contains many important status and debugging messages.   However, if you really want to, you can: To disable access.log:

            cache_log /dev/null
  • Mount SMB share to QNAP

    1. Connect to QNAP over SSH

    2. Create mount point:

    mkdir /share/Public/mntdir

    3. Mount share:

    mount.cifs //IP-OF-SHARE-SERVER/FOLDER /share/Public/mntdir/ -o sec=ntlm,username=USER,password=PASSWORD

  • Find Out *nux Distribution Name and Version

     

    cat /etc/*-release

    uname -a

    uname -mrs

  • Crontab usage on *nix platform

    Cron is a daemon that executes scheduled commands.
    Cron reads /etc/crontab.
    Cron wakes up every minute, examining all stored crontabs, checking each command to see if it should be run in the current minute.
    When executing commands, any output is mailed to the owner of the crontab.
    You should use absolute path names for commands like /bin/ls. This is to insure you call the correct command.

    # Minute   Hour   Day of Month       Month          Day of Week        Command   
    # (0-59)  (0-23)     (1-31)    (1-12 or Jan-Dec)  (0-6 or Sun-Sat)               
        0        2          12             *                *            /usr/bin/find

    0 0 1 1 * - Run once a year
    0 0 1 * * - Run once a month
    0 0 * * 0 - Run once a week
    0 0 * * * - Run once a day
    0 * * * * - Run once an hour

     

     

AustIT Remote Support

Who's Online

We have 430 guests and no members online

Google AdSence

AUST IT - Computer help out of hours, when you need it most.

Find out why we do it for less.

About

AUST IT will help you resolve any technical support issues you are facing onsite or remotely via remote desktop 24/7. More...

Contacts

Reservoir, Melbourne,
3073, VIC, Australia

Phone: 0422 348 882

This email address is being protected from spambots. You need JavaScript enabled to view it.

Sydney: 0481 837 077

Connect

Join us in social networks to be in touch.

Newsletter

Complete the form below, and we'll send you our emails with all the latest AUST IT news.