-
Notifications
You must be signed in to change notification settings - Fork 11
/
restore_config.yml
30 lines (30 loc) · 958 Bytes
/
restore_config.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
---
#restore_config.yml
- name: RESTORE CONFIGURATION
hosts: cisco
gather_facts: no
vars:
src_folder: "files/default_configs"
src: "{{ src_folder }}/{{ inventory_hostname }}.cfg"
dest: "{{ inventory_hostname }}.cfg"
options: "-o StrictHostKeyChecking=no"
tasks:
- name: CHECK THAT CONFIG FILE EXISTS
stat:
path: "{{ src }}"
register: stat_result
- name: RESTORE THE CONFIG
block:
- name: COPY RUNNING CONFIG TO THE DEVICE
command: "sshpass -p {{ ansible_ssh_pass }} scp {{ options }} {{ src }} {{ inventory_hostname }}:/{{ dest }}"
register: copy_output
- name: CONFIG REPLACE
ios_command:
commands:
- config replace flash:{{ dest }} force
when: stat_result.stat.exists
- name: ERASE REMOTE CONFIG FILE
ios_command:
commands:
- "delete /force flash:/{{ dest }}"
when: copy_output.rc == 0