Backup and Tech support using Ansible

Making use of Ansible to collect backup files ,show tech and see the versions of Cisco switches. I use docker container to run the ansible playbooks.

Inventory file:-

Create an inventory file

[switches]
R1  ansible_host=10.60.51.1


[switches:vars]
ansible_connection=network_cli
ansible_network_os=ios
ansible_user=admin
ansible_password=cisco
ansible_become=yes
ansible_become_method=enable

Yaml File:-

Create a yaml file. The below code will save the Backup and show tech file on the root folder with the device name.

---
- name: Cisco ios devices
  hosts: switches
  gather_facts: no
  connection: network_cli
 
  tasks:
    - name: Backup 
      ios_command:
        commands:
          - show running-config
          - show tech-support 
          
      register: cisco_config
 
 
    - name: Save the config
      copy:
        content: "{{ cisco_config.stdout[0] }}"
        dest: "~/{{ inventory_hostname }}_backup.txt"
 
    - name: Get show tech support
      copy:
        content: "{{ cisco_config.stdout[1] }}"
        dest: "~/{{ inventory_hostname }}_show_tech.txt"

  
 
    - name: CHECK CURRENT VERSION
      ios_facts:
 
    - debug:
        msg:
        - "Current version is {{ ansible_net_version }}"
        
 


...

Run Ansible Playbook:-

ansible-playbook -i inventory version.yaml

One Comment Add yours

  1. Sukriti says:

    Hello,

    Thank you for sharing the blogs with us. This is one of the best way to take backup and tech support using ansible.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s