Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Add other platforms #1

Merged
merged 10 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
changelog_filename_template: ../CHANGELOG.rst
changelog_filename_version_depth: 0
changes_file: changelog.yaml
Expand Down
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors:
- Sagar Paul (@KB-perByte)
dependencies:
ansible.netcommon: ">=6.1.0"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to be updated with platform-specific releases

ansible.netcommon: ">=6.0.0"
ansible.utils: ">=3.0.0"
license_file: LICENSE
name: restore
Expand Down
6 changes: 3 additions & 3 deletions roles/run/includes/cli_restore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
prepare_path: "{{ role_path }}/includes/prepare"
delete_path: "{{ role_path }}/includes/delete"
health_check_path: "{{ role_path }}/includes/health_checks"
network_os: "{{ ansible_network_os.split('.')[2] }}"
delete_backup_from_dest: false

- name: Check if file copy is possible
Expand All @@ -16,15 +15,16 @@
ansible.netcommon.net_put:
src: "{{ network_backup_path }}"
protocol: scp
dest: "flash:{{ file_name }}.txt"
dest: "{{ dest_dir }}{{ file_name }}.txt"

- name: Prepare appliance for a restore operation
ansible.builtin.include_tasks: "{{ prepare_path }}/{{ network_os }}.yaml"

- name: Restore operation
- name: Restore operation for {{ network_os }}
ansible.netcommon.cli_restore:
force: true
filename: "{{ file_name }}.txt"
path: "{{ appliance_dir }}"

- name: Delete backup from appliance
ansible.builtin.include_tasks: "{{ delete_path }}/{{ network_os }}.yaml"
Expand Down
5 changes: 5 additions & 0 deletions roles/run/includes/cli_restore/eos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Restore the config
arista.eos.eos_config:
replace: config
src: "{{ network_backup_path }}"
5 changes: 5 additions & 0 deletions roles/run/includes/cli_restore/junos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Restore operation for {{ network_os }}
junipernetworks.junos.junos_config:
update: replace
src: "{{ network_backup_path }}"
7 changes: 7 additions & 0 deletions roles/run/includes/cli_restore_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Set content specific facts
ansible.builtin.set_fact:
cli_restore_path: "{{ role_path }}/includes/cli_restore"

- name: Invoke restore operation
ansible.builtin.include_tasks: "{{ cli_restore_path }}/{{ network_os }}.yaml"
17 changes: 17 additions & 0 deletions roles/run/includes/common/healthcheck_common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
- name: Check restore file size
ansible.builtin.stat:
path: "{{ network_backup_path }}"
register: restore_file_data

- name: Inspect appliance size
ansible.builtin.debug:
var: appliance_dir_data

- name: Inspect restore file size
ansible.builtin.debug:
var: restore_file_data

- name: Assert file sizes
assert:
that: restore_file_data.stat.size < appliance_dir_data.free_bytes
1 change: 0 additions & 1 deletion roles/run/includes/common/validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
- "eos"
- "nxos"
- "iosxr"
- "vyos"

- name: Conditional test
ansible.builtin.include_tasks: "includes/common/unsupported_platform.yaml"
Expand Down
4 changes: 1 addition & 3 deletions roles/run/includes/delete/ios.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
- name: Delete the backup file post backup
cisco.ios.ios_command:
commands:
- command: "delete /force flash:{{ file_name }}.txt"
# prompt: Delete bootflash:/{{ file_name }}.txt\? \[confirm\]
# answer: "y"
- command: "delete /force {{ dest_dir }}{{ file_name }}.txt"
5 changes: 5 additions & 0 deletions roles/run/includes/delete/iosxr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Delete the backup file post backup
cisco.iosxr.iosxr_command:
commands:
- command: "delete {{ dest_dir }}{{ file_name }}.txt"
5 changes: 5 additions & 0 deletions roles/run/includes/delete/nxos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Delete the backup file post backup
cisco.nxos.nxos_command:
commands:
- command: "delete {{ appliance_dir }}{{ file_name }}.txt no-prompt"
23 changes: 7 additions & 16 deletions roles/run/includes/health_checks/ios.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
---
- name: Set IOSXE directory - content specific facts
ansible.builtin.set_fact:
dest_dir: "flash:"
appliance_dir: "flash://"

- name: Parse free space information
ansible.utils.cli_parse:
command: "dir /all | section free"
Expand All @@ -7,19 +12,5 @@
template_path: "{{ tmplt_path }}/{{ network_os }}.yaml"
set_fact: appliance_dir_data

- name: Check restore file size
ansible.builtin.stat:
path: "{{ network_backup_path }}"
register: restore_file_data

- name: Inspect appliance size
debug:
var: appliance_dir_data

- name: Inspect restore file size
debug:
var: restore_file_data

- name: Assert file sizes
assert:
that: restore_file_data.stat.size < appliance_dir_data.free_bytes
- name: Include task to compare file size with free space
ansible.builtin.include_tasks: "includes/common/healthcheck_common.yaml"
34 changes: 34 additions & 0 deletions roles/run/includes/health_checks/iosxr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: Set IOSXR directory - content specific facts
ansible.builtin.set_fact:
dest_dir: "/misc/scratch/"
appliance_dir: ""

- name: Parse free space information
ansible.utils.cli_parse:
command: "dir /all | include free"
parser:
name: ansible.netcommon.content_templates
template_path: "{{ tmplt_path }}/{{ network_os }}.yaml"
set_fact: appliance_dir_data

- name: Check restore file size
ansible.builtin.stat:
path: "{{ network_backup_path }}"
register: restore_file_data

- name: Make appliance data unit relevant
ansible.builtin.set_fact:
applinace_data_dir_bytes: "{{ appliance_dir_data.free_bytes * 1024 }}"

- name: Inspect appliance size
ansible.builtin.debug:
var: appliance_dir_data

- name: Inspect restore file size
ansible.builtin.debug:
var: restore_file_data

- name: Assert file sizes
assert:
that: restore_file_data.stat.size < applinace_data_dir_bytes
16 changes: 16 additions & 0 deletions roles/run/includes/health_checks/nxos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: Set NXOS directory - content specific facts
ansible.builtin.set_fact:
dest_dir: "bootflash:/"
appliance_dir: "bootflash:///"

- name: Parse free space information
ansible.utils.cli_parse:
command: "dir | include free"
parser:
name: ansible.netcommon.content_templates
template_path: "{{ tmplt_path }}/{{ network_os }}.yaml"
set_fact: appliance_dir_data

- name: Include task to compare file size with free space
ansible.builtin.include_tasks: "includes/common/healthcheck_common.yaml"
10 changes: 10 additions & 0 deletions roles/run/includes/health_checks/templates/iosxr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# fmt: off
[
{
"name": "free_space",
"getval": '''(?P<total_bytes>\d+)\skbytes\stotal\s\((?P<free_bytes>\d+)\skbytes\sfree\)''',
"result":
{ "total_bytes": "{{ total_bytes }}", "free_bytes": "{{ free_bytes }}" },
},
]
# fmt: on
10 changes: 10 additions & 0 deletions roles/run/includes/health_checks/templates/nxos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# fmt: off
[
{
"name": "free_space",
"getval": '''(?P<total_bytes>\d+)\sbytes\sfree''',
"result":
{ "total_bytes": "{{ total_bytes }}", "free_bytes": "{{ free_bytes }}" },
},
]
# fmt: on
18 changes: 17 additions & 1 deletion roles/run/includes/network.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
---
- name: Set supported platform list
ansible.builtin.set_fact:
supported_cli_restore:
- "junos"
- "eos"
supported_plugin_restore:
- "nxos"
- "iosxr"
- "ios"
network_os: "{{ ansible_network_os.split('.')[2] }}"

- name: Invoke backup task
ansible.builtin.include_tasks: includes/cli_restore.yaml
ansible.builtin.include_tasks: "includes/cli_restore.yaml"
when: network_os not in supported_cli_restore

- name: Invoke cli specific backup task
ansible.builtin.include_tasks: "includes/cli_restore_config.yaml"
when: network_os not in supported_plugin_restore
10 changes: 5 additions & 5 deletions roles/run/includes/prepare/ios.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
- name: Prepare appliance for restore
ansible.builtin.debug:
msg:
- "Task to prepare appliance for restore operation"

- name: Overwrite startup config - archive
cisco.ios.ios_config:
lines:
- "archive"

- name: Dir the flash
cisco.ios.ios_command:
commands:
- command: "dir"
5 changes: 5 additions & 0 deletions roles/run/includes/prepare/iosxr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Prepare appliance for restore
ansible.builtin.debug:
msg:
- "Task to prepare appliance for restore operation"
5 changes: 5 additions & 0 deletions roles/run/includes/prepare/nxos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Prepare appliance for restore
ansible.builtin.debug:
msg:
- "Task to prepare appliance for restore operation"
Loading