Back up router and switch configs automatically with Ansible

September 23, 2026 ยท DevOps

When a switch dies, the config is the part that takes time to rebuild. A scheduled backup makes replacement a copy-and-paste job.

Inventory

[switches]
sw-core-01 ansible_host=10.0.0.2
sw-access-01 ansible_host=10.0.0.11

[switches:vars]
ansible_connection=network_cli
ansible_network_os=cisco.ios.ios

Playbook

- hosts: switches
  gather_facts: false
  tasks:
    - name: Back up running config
      cisco.ios.ios_config:
        backup: true
        backup_options:
          dir_path: ./backups

Run it with ansible-playbook -i inventory backup.yml, schedule it with cron, and commit the backups folder to Git. Every change then shows up as a readable diff.

Tell us what you are building or fixing.

We reply within one working day.

Contact us