Skip to content

Instantly share code, notes, and snippets.

@craigarms
Created February 19, 2020 09:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save craigarms/01f10cd417f4efa5000927293b3cbb55 to your computer and use it in GitHub Desktop.
Save craigarms/01f10cd417f4efa5000927293b3cbb55 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