Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
playbook to backup network device running configuration to local file
---
- hosts: ios
connection: local
vars:
backup_root: /tmp/backups
cli:
host: "{{ inventory_hostname }}"
username: cisco
password: cisco
transport: cli
tasks:
- name: run show running-config on remote devices
ios_command:
commands: show running
provider: "{{ cli }}"
register: config
- name: ensure backup folder is created
file:
path: "{{ backup_root }}"
state: directory
run_once: yes
- name: ensure device rolder is created
file:
path: "{{ backup_root }}/{{ inventory_hostname }}"
state: directory
- name: get timestamp
command: date +%Y%m%d
register: timestamp
- copy:
content: "{{ config.stdout[0] }}"
dest: "{{ backup_root }}/{{ inventory_hostname }}/running-config_{{ timestamp.stdout }}"
@itbj

This comment has been minimized.

Copy link
Owner Author

@itbj itbj commented Nov 20, 2019

成功运行!不错。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment