1344
This commit is contained in:
@@ -672,79 +672,54 @@
|
||||
when: not (dhcp_migrated_ok | bool)
|
||||
ansible.builtin.meta: end_host
|
||||
|
||||
# ============================ CASE A CLEANUP: CANCEL PENDING REBOOT ============================
|
||||
- name: CASE A | Initialize cumulative cleanup report
|
||||
# ============================ CASE A CLEANUP (DHCP OK, NO PPP) ============================
|
||||
|
||||
- name: CASE A Initialize cumulative cleanup report
|
||||
when: dhcp_migrated_ok | bool
|
||||
delegate_to: localhost
|
||||
ansible.builtin.set_fact:
|
||||
cleanup_report: "case A observed"
|
||||
case_a_report: "case A observed"
|
||||
changed_when: false
|
||||
|
||||
- name: "CASE A | DEV2 detect pending reboot processes (best-effort)"
|
||||
- name: CASE A DEV2 detect pending reboot process
|
||||
when: dhcp_migrated_ok | bool
|
||||
delegate_to: localhost
|
||||
ansible.builtin.shell: |
|
||||
# BusyBox-friendly: look for delayed reboot patterns.
|
||||
export DEV2_CMD="ps w 2>/dev/null | grep -E '[r]eboot( |$)|[n]ohup reboot' || true"
|
||||
export DEV2_CMD="ps w | grep eboot | grep -v grep >/dev/null 2>&1 && echo YES || echo NO"
|
||||
{{ dev2_exec_cmd }}
|
||||
args: { executable: /bin/bash }
|
||||
register: reboot_ps
|
||||
register: reboot_detect
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: "CASE A | DEV2 cancel pending reboot if found (kill reboot PIDs)"
|
||||
when: dhcp_migrated_ok | bool
|
||||
- name: CASE A DEV2 cancel pending reboot if found
|
||||
when:
|
||||
- dhcp_migrated_ok | bool
|
||||
- (reboot_detect.stdout | trim) == "YES"
|
||||
delegate_to: localhost
|
||||
ansible.builtin.shell: |
|
||||
set -e
|
||||
# Extract PID from BusyBox ps output: assume PID is the first column.
|
||||
# Only target lines that clearly include "reboot" or "nohup reboot".
|
||||
PIDS="$(printf '%s\n' "{{ reboot_ps.stdout | default('') | regex_replace('\r','') }}" \
|
||||
| grep -E '(^| )reboot( |$)|nohup reboot' \
|
||||
| awk '{print $1}' \
|
||||
| grep -E '^[0-9]+$' \
|
||||
| sort -u || true)"
|
||||
|
||||
if [ -z "$PIDS" ]; then
|
||||
echo "NONE"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Try TERM then KILL.
|
||||
for p in $PIDS; do
|
||||
kill "$p" 2>/dev/null || true
|
||||
done
|
||||
sleep 1
|
||||
for p in $PIDS; do
|
||||
kill -9 "$p" 2>/dev/null || true
|
||||
done
|
||||
|
||||
echo "$PIDS"
|
||||
export DEV2_CMD="killall reboot 2>/dev/null || true"
|
||||
{{ dev2_exec_cmd }}
|
||||
args: { executable: /bin/bash }
|
||||
register: reboot_kill
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: CASE A | Append reboot cancellation result to cleanup report
|
||||
- name: CASE A append reboot cancellation result
|
||||
when: dhcp_migrated_ok | bool
|
||||
delegate_to: localhost
|
||||
ansible.builtin.set_fact:
|
||||
cleanup_report: >-
|
||||
{{
|
||||
cleanup_report ~
|
||||
(
|
||||
('; pending reboot found, cancelled (pids=' ~ (reboot_kill.stdout | trim) ~ ')')
|
||||
if ((reboot_kill.stdout | default('') | trim) not in ['','NONE'])
|
||||
else
|
||||
'; no pending reboot found'
|
||||
)
|
||||
}}
|
||||
case_a_report: >-
|
||||
{{ case_a_report
|
||||
~ '; pending reboot '
|
||||
~ ((reboot_detect.stdout | trim) == 'YES'
|
||||
| ternary('found and cancelled', 'not found')) }}
|
||||
changed_when: false
|
||||
|
||||
- name: CASE A | Final cumulative cleanup report
|
||||
- name: CASE A final cumulative cleanup report
|
||||
when: dhcp_migrated_ok | bool
|
||||
delegate_to: localhost
|
||||
ansible.builtin.debug:
|
||||
msg:
|
||||
- "{{ cleanup_report }}"
|
||||
- "{{ case_a_report }}"
|
||||
changed_when: false
|
||||
|
||||
|
||||
Reference in New Issue
Block a user