Added playbook for backing up device configuration with timestamps

This commit is contained in:
Vlad Raducanu 2021-04-22 09:37:48 +01:00
parent b3f9331a12
commit f3939d26f2
3 changed files with 87 additions and 2 deletions

View File

@ -1,7 +1,7 @@
---
## Playbook for reading and printing device information
## This playbook collects the device facts and prints out key information
- name: First playbook - reads and prints device info
- name: Audit devices and print key information
hosts: homekit
gather_facts: false
connection: network_cli
@ -19,6 +19,38 @@
debug:
msg: "{{ current_config.ansible_facts.ansible_net_hostname }} is reachable and the OS is {{ current_config.ansible_facts.ansible_net_version }}. SN is {{ current_config.ansible_facts.ansible_net_serialnum }}. Model is {{current_config.ansible_facts.ansible_net_model }}"
- name: Collect interface, routing and IOX runtime information
ios_command:
commands:
- show ip interface brief
- show interface description
- show ip route
- show ip arp
- show iox
register: runtime_information
- name: Print interface information
debug:
var: runtime_information.stdout_lines[0]
- name: Print interface description
debug:
var: runtime_information.stdout_lines[1]
- name: Print routing information
debug:
var: runtime_information.stdout_lines[2]
- name: Print ARP information
debug:
var: runtime_information.stdout_lines[3]
- name: Print IOx information
debug:
var: runtime_information.stdout_lines[4]

View File

@ -0,0 +1,24 @@
---
## This playbook backs up the device configuration
- name: Backup device configuration with timestamps
hosts: homekit
gather_facts: false
connection: network_cli
roles:
- common
tasks:
- name: Collect device facts
ios_facts:
gather_subset: all
register: current_config
- name: Save configuration and back it up to local folder
ios_config:
backup: yes
backup_options:
dir_path: ../../ansible_backups/
filename: "{{ current_config.ansible_facts.ansible_net_hostname }}-{{ '%Y-%m-%d' | strftime }}-{{ '%H:%M:%S' | strftime }}.backup"

View File

@ -0,0 +1,29 @@
---
## Playbook for reading and printing device information
- name: Collect device facts and print formatted and unformatted information
hosts: homekit
gather_facts: false
connection: network_cli
roles:
- common
tasks:
- name: Collect device configuration
ios_facts:
gather_subset: all
register: current_config
- name: Print device identity info
debug:
msg: "{{ current_config.ansible_facts.ansible_net_hostname }} is reachable and the OS is {{ current_config.ansible_facts.ansible_net_version }}. SN is {{ current_config.ansible_facts.ansible_net_serialnum }}. Model is {{current_config.ansible_facts.ansible_net_model }}"
- name: Print contents of current_config object
debug:
var: current_config