• 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 %}
  • OpenHUB - Automation

    Just quickly tested Home Assistance and foud that it required reqular payment for cloud access. So, 3 ways to acces remotely:

    - Subscription for cloud (5$/month)
    - Open port on home router (not safe)
    - Use VPN to home to have access to the system (not flexible).

     Next step is test OpenHUB.

    1. Installation is simple:

    - Download latest image
    - Put image in the SD using BalenaEtcher
    - Boot and leave the RasperiPi for on hour, all installation fille done

    1.1. SSH access and pre-configuration.

    - SSH to the system (openhubian:openhabian)
    - sudo openhabian-config
    - 01.Upgrade
    - 02.Upgrade System
    - install 21.Log Viewer (useful for troubleshooting)
    - install 23.Masquitto (powerfull message broker fo communocate with devices)
    - 32.Set System Locate (Choose AU)
    - 33.Set System TimeZone

    2. Configuration
    It is useful to start with demo configuration preinstalled. If you forget to choose demo package on the installation process, simply edit "package = demo" in the /etc/openhab2/service/addons.cfg and reboot the system.

    - Configuration files location: /etc/openhab2/
    (Use Visual Studio Code with openHAB extention to edit files)

     

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.