From f3939d26f2096be652757168bfce8f16c3e1f4ff Mon Sep 17 00:00:00 2001 From: Vlad Raducanu Date: Thu, 22 Apr 2021 09:37:48 +0100 Subject: [PATCH] Added playbook for backing up device configuration with timestamps --- ios_devices/device_audit.yml | 36 +++++++++++++++++++++++++++++-- ios_devices/device_backup.yml | 24 +++++++++++++++++++++ ios_devices/test_device_audit.yml | 29 +++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 ios_devices/device_backup.yml create mode 100644 ios_devices/test_device_audit.yml diff --git a/ios_devices/device_audit.yml b/ios_devices/device_audit.yml index d99baf5..98841d7 100644 --- a/ios_devices/device_audit.yml +++ b/ios_devices/device_audit.yml @@ -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] + + diff --git a/ios_devices/device_backup.yml b/ios_devices/device_backup.yml new file mode 100644 index 0000000..85201c5 --- /dev/null +++ b/ios_devices/device_backup.yml @@ -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" + \ No newline at end of file diff --git a/ios_devices/test_device_audit.yml b/ios_devices/test_device_audit.yml new file mode 100644 index 0000000..afa5c14 --- /dev/null +++ b/ios_devices/test_device_audit.yml @@ -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 + + + + + \ No newline at end of file