Ansible: How to take CISCO switch backup?
Device configuration backup is vital task for IT people especially those who are working as a administrator. To make this task easier i have create Ansible playbook for CISCO switches. Below i will show how this playbook actually works.
vim /etc/ansible/hosts
# Insert below lines at the end of the file.
[cisco]
SW-148 ansible_host=192.168.11.148 ansible_network_os=ios
:wq
cd /etc/ansible/playbooks
vim cisco-sw-bkp.yaml
---
- hosts: all
gather_facts: true
connection: network_cli
become: yes
tasks:
- name: Show Running Configuration
ios_command:
host: "{{ cisco }}"
commands:
- show run
register: config
- name: Save output to /etc/ansible/backups
copy:
content: "{{ config.stdout[0] }}"
dest: "/etc/ansible/backups/show_run_config_{{ inventory_hostname }}.txt"
:wq
Run The Playbook
# ansible-playbook -l cisco playbooks/cisco.yaml -k -u admin
If everything is ok. You will get a backup file in /etc/ansible/backups/ location named as show_run_config_192.168.11.148.txt
If you do not want to type password during playbook execution you have to modify your playbook as like below:
# vim /etc/ansible/hosts
[cisco]
SW-148 ansible_host=192.168.11.148 ansible_network_os=ios ansible_ssh_user=admin ansible_ssh_pass="admin"
Then run the playbook
# ansible-playbook -l cisco playbooks/cisco.yaml
Comments