From 7ed34c13fb090ddaf274ffe765c60249b46ba843 Mon Sep 17 00:00:00 2001 From: mreiger Date: Fri, 4 Oct 2024 19:15:46 +0200 Subject: [PATCH 1/4] Add role to boot a SONIC device into ONIE --- partition/roles/sonic-boot-to-onie/README.md | 11 +++++++++ .../sonic-boot-to-onie/defaults/main.yaml | 2 ++ .../roles/sonic-boot-to-onie/tasks/main.yaml | 24 +++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 partition/roles/sonic-boot-to-onie/README.md create mode 100644 partition/roles/sonic-boot-to-onie/defaults/main.yaml create mode 100644 partition/roles/sonic-boot-to-onie/tasks/main.yaml diff --git a/partition/roles/sonic-boot-to-onie/README.md b/partition/roles/sonic-boot-to-onie/README.md new file mode 100644 index 00000000..f632ab5b --- /dev/null +++ b/partition/roles/sonic-boot-to-onie/README.md @@ -0,0 +1,11 @@ +# sonic-boot-to-onie + +Boots a SONiC switch into ONIE so it can be reinstalled from scratch. + +It depends on the `switch_facts` module from `ansible-common`, so make sure modules from `ansible-common` are included before executing this role. + +## Variables + +| Name | Mandatory | Description | +| ----------------------------- | --------- | -------------------------------------------------------------------------------- | +| sonic_boot_to_onie_bootentry | yes | The efi boot entry number for the ONIE boot entry as seen with `efibootmgr`. | diff --git a/partition/roles/sonic-boot-to-onie/defaults/main.yaml b/partition/roles/sonic-boot-to-onie/defaults/main.yaml new file mode 100644 index 00000000..e6a975c8 --- /dev/null +++ b/partition/roles/sonic-boot-to-onie/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +sonic_boot_to_onie_bootentry: "0001" diff --git a/partition/roles/sonic-boot-to-onie/tasks/main.yaml b/partition/roles/sonic-boot-to-onie/tasks/main.yaml new file mode 100644 index 00000000..f2ebdcf7 --- /dev/null +++ b/partition/roles/sonic-boot-to-onie/tasks/main.yaml @@ -0,0 +1,24 @@ +--- +- name: Gather switch facts + switch_facts: + +- name: Check mandatory variables for this role are set + assert: + fail_msg: "not all mandatory variables given, check role documentation" + quiet: yes + that: + - sonic_boot_to_onie_bootentry is defined + - metal_stack_switch_os_is_sonic + +- name: Set next boot entry to ONIE + command: efibootmgr -n {{ sonic_boot_to_onie_bootentry }} + +- name: Boot into ONIE + reboot: + +- name: Wait until ZTP has completed + shell: "show ztp status" + register: result + until: "'SUCCESS' in result.stdout" + retries: 30 + delay: 20 From c1ba215c74689f5ea1bd4516817c84e0a26b60dd Mon Sep 17 00:00:00 2001 From: mreiger Date: Fri, 4 Oct 2024 20:11:52 +0200 Subject: [PATCH 2/4] Wait after reboot command to prevent checking for ZTP before the reboot actually happened --- partition/roles/sonic-boot-to-onie/tasks/main.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/partition/roles/sonic-boot-to-onie/tasks/main.yaml b/partition/roles/sonic-boot-to-onie/tasks/main.yaml index f2ebdcf7..2d5280d9 100644 --- a/partition/roles/sonic-boot-to-onie/tasks/main.yaml +++ b/partition/roles/sonic-boot-to-onie/tasks/main.yaml @@ -15,6 +15,7 @@ - name: Boot into ONIE reboot: + post_reboot_delay: 60 - name: Wait until ZTP has completed shell: "show ztp status" From 14011bc2f9f248a081cdf4164ce7cd702e80271e Mon Sep 17 00:00:00 2001 From: mreiger Date: Fri, 4 Oct 2024 20:13:59 +0200 Subject: [PATCH 3/4] Revert "Wait after reboot command to prevent checking for ZTP before the reboot actually happened" This reverts commit c1ba215c74689f5ea1bd4516817c84e0a26b60dd. --- partition/roles/sonic-boot-to-onie/tasks/main.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/partition/roles/sonic-boot-to-onie/tasks/main.yaml b/partition/roles/sonic-boot-to-onie/tasks/main.yaml index 2d5280d9..f2ebdcf7 100644 --- a/partition/roles/sonic-boot-to-onie/tasks/main.yaml +++ b/partition/roles/sonic-boot-to-onie/tasks/main.yaml @@ -15,7 +15,6 @@ - name: Boot into ONIE reboot: - post_reboot_delay: 60 - name: Wait until ZTP has completed shell: "show ztp status" From ccd4c676191b8dc01ebd7deaa81cb8b042eb9967 Mon Sep 17 00:00:00 2001 From: mreiger Date: Mon, 7 Oct 2024 10:23:17 +0200 Subject: [PATCH 4/4] Use command instead of shell as recommended --- partition/roles/sonic-boot-to-onie/tasks/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/partition/roles/sonic-boot-to-onie/tasks/main.yaml b/partition/roles/sonic-boot-to-onie/tasks/main.yaml index f2ebdcf7..29d6e07f 100644 --- a/partition/roles/sonic-boot-to-onie/tasks/main.yaml +++ b/partition/roles/sonic-boot-to-onie/tasks/main.yaml @@ -17,7 +17,7 @@ reboot: - name: Wait until ZTP has completed - shell: "show ztp status" + command: "show ztp status" register: result until: "'SUCCESS' in result.stdout" retries: 30