By Glenn McCallum

Ansible backup Cisco Configuration

Quick byte on how to backup a Cisco running-configuration using ansible.

Please refer to earlier post about setting up ansible and using devnet routers as example to use as test lab for our playbooks.

Create Playbook

Create a new playbook named backup_config.yml and add in the following

---

- hosts: routers
  gather_facts: no
  connection: network_cli

  tasks:

  - name: BACKUP RUNNING CONFIG
    ios_config:
      backup: yes

The above will backup the hosts under “routers” we added previously in other post.

Run the playbook

Running the playbook backup_config.yml

root@macka-VirtualBox:/etc/ansible# ansible-playbook backup_config.yml 

PLAY [routers] ************************************************************************************************************

TASK [BACKUP RUNNING CONFIG] **********************************************************************************************
changed: [sandbox-iosxe-latest-1.cisco.com]
fatal: [sandbox-iosxe-recomm-1.cisco.com]: FAILED! => {"changed": false, "msg": "Error reading SSH protocol banner[Errno 104] Connection reset by peer"}

PLAY RECAP ****************************************************************************************************************
sandbox-iosxe-latest-1.cisco.com : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
sandbox-iosxe-recomm-1.cisco.com : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

root@macka-VirtualBox:/etc/ansible#

We actually see that one device completed successfully and the other failed (router was offline at the time)

Check the backups

By default backups are stored in backups directory

root@macka-VirtualBox:/etc/ansible# cd backup/
root@macka-VirtualBox:/etc/ansible/backup# ls -al
total 20
drwxr-xr-x 2 root root 4096 Aug 15 16:53 .
drwxr-xr-x 4 root root 4096 Aug 14 22:52 ..
-rw-r--r-- 1 root root 9822 Aug 15 16:53 sandbox-iosxe-latest-1.cisco.com_config.2021-08-15@16:53:25
root@macka-VirtualBox:/etc/ansible/backup# 

Yml file can be downloaded from
https://github.com/glennmccallum/Ansible

Share this:
Ansible, Cisco, Scripting 0

Leave a Reply

Your email address will not be published. Required fields are marked *