Ansible-playbook for backing up running config of Cisco IOS

This ansible-playbook can be used to backup running configuration from Cisco IOS devices. You can refer to my earlier post Getting Started with your first ansible-playbook for Network Automation to know about the parameters used in this playbook.


Inventory file

# Inventory file for Ansible
[XE]
ios-xe-mgmt.cisco.com:8181
ios-xe-mgmt-latest.cisco.com:8181
[XR]
sbx-iosxr-mgmt.cisco.com:8181
[all:vars]
ansible_network_os=ios


Playbook

---
- name: Define Parameters
  hosts: XE
  gather_facts: no
  connection: network_cli
  tasks:
   - name: backup the config
     ios_config:
      backup: yes
     register: backup_config
   - name: Store the config to directory
     copy:
      src: "{{ backup_config.backup_path }}"
      dest: "/tmp/backups/{{ inventory_hostname }}"



Running the playbook

[prashant@Prashant-VM01 ~]$ ansible-playbook play03.yml -i /home/prashant/inventory -u developer -k
SSH password:
PLAY [Define Parameters] **********************************************************************************************************
TASK [backup the config] **********************************************************************************************************
changed: [ios-xe-mgmt-latest.cisco.com]
changed: [ios-xe-mgmt.cisco.com]
TASK [Store the config to directory] **********************************************************************************************
changed: [ios-xe-mgmt.cisco.com]
changed: [ios-xe-mgmt-latest.cisco.com]
PLAY RECAP ************************************************************************************************************************
ios-xe-mgmt-latest.cisco.com : ok=2    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
ios-xe-mgmt.cisco.com      : ok=2    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0


Verifying the backup files 

[prashant@Prashant-VM01 ~]$ cd /tmp/backups
[prashant@Prashant-VM01 backups]$ ls
ios-xe-mgmt.cisco.com  ios-xe-mgmt-latest.cisco.com
[prashant@Prashant-VM01 backups]$

Comments

  1. Update to cisco.ios.ios_config: and you are golden

    ReplyDelete
  2. Sounds like this

    - name: backup running config on the routers
    cisco.ios.ios_config:
    backup: yes
    backup_options:
    filename: "{{ inventory_hostname }}_backup.cfg"
    dir_path: /home/osboxes/Documents

    ReplyDelete

Post a Comment

Popular posts from this blog

Filtering Routes in BGP using Route-maps and Prefix-list

Ansible-Playbook to display output of multiple show commands (using stdout_lines with Loop)

Export or Backup Azure Virtual Networks or Subnet information into CSV using PowerShell

Ansible Playbook for Network OS Upgrade with pre and post checks

Export or Backup Azure Route Table into CSV using PowerShell

Cisco ASA Active/Active Failover Configuration

VMware NSX Traffic Flow — East-West & North-South

Get Model Number and Serial number of Cisco devices using ios_facts module

Download Visio Stencils for Network Topology