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