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 %}

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.