Skip to content

Instantly share code, notes, and snippets.

@pr0b3r7
Forked from craigarms/cisco_device_backup.yml
Created July 15, 2021 14:45
Show Gist options
  • Save pr0b3r7/c7888c45b128c381df01ccfbd71db244 to your computer and use it in GitHub Desktop.
Save pr0b3r7/c7888c45b128c381df01ccfbd71db244 to your computer and use it in GitHub Desktop.
Ansible playbook to Idempotently retrieve and backup information from Cisco Devices
---
- hosts: sw_ios
gather_facts: false
connection: local
tasks:
- name: save config
ios_command:
commands:
- write mem
timeout: 60
vars:
ansible_command_timeout: 60
- name: show run
ios_command:
commands:
- show run | e NVRAM
timeout: 60
register: shrun
vars:
ansible_command_timeout: 60
- name: show vlan
ios_command:
commands: show vlan
register: shvlan
- name: show inv
ios_command:
commands: show inventory
register: shinv
- name: show version
ios_command:
commands: show version | e ptime|restarted
register: shver
- name: show vtp status
ios_command:
commands: show vtp status
register: shvtp
- blockinfile:
block: "{{ item.value }}"
dest: "/backups/{{ inventory_hostname }}.txt"
marker: "# {mark} ANSIBLE MANAGED BLOCK {{item.variable }}"
create: yes
with_items:
- variable: config
value: "{{ shrun.stdout[0] }}"
- variable: vlan
value: "{{ shvlan.stdout[0] }}"
- variable: inventory
value: "{{ shinv.stdout[0] }}"
- variable: version
value: "{{ shver.stdout[0] }}"
- variable: vtp
value: "{{ shvtp.stdout[0] }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment