1344
This commit is contained in:
@@ -672,79 +672,54 @@
|
|||||||
when: not (dhcp_migrated_ok | bool)
|
when: not (dhcp_migrated_ok | bool)
|
||||||
ansible.builtin.meta: end_host
|
ansible.builtin.meta: end_host
|
||||||
|
|
||||||
# ============================ CASE A CLEANUP: CANCEL PENDING REBOOT ============================
|
# ============================ CASE A CLEANUP (DHCP OK, NO PPP) ============================
|
||||||
- name: CASE A | Initialize cumulative cleanup report
|
|
||||||
|
- name: CASE A Initialize cumulative cleanup report
|
||||||
when: dhcp_migrated_ok | bool
|
when: dhcp_migrated_ok | bool
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
cleanup_report: "case A observed"
|
case_a_report: "case A observed"
|
||||||
changed_when: false
|
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
|
when: dhcp_migrated_ok | bool
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
ansible.builtin.shell: |
|
ansible.builtin.shell: |
|
||||||
# BusyBox-friendly: look for delayed reboot patterns.
|
export DEV2_CMD="ps w | grep eboot | grep -v grep >/dev/null 2>&1 && echo YES || echo NO"
|
||||||
export DEV2_CMD="ps w 2>/dev/null | grep -E '[r]eboot( |$)|[n]ohup reboot' || true"
|
|
||||||
{{ dev2_exec_cmd }}
|
{{ dev2_exec_cmd }}
|
||||||
args: { executable: /bin/bash }
|
args: { executable: /bin/bash }
|
||||||
register: reboot_ps
|
register: reboot_detect
|
||||||
changed_when: false
|
changed_when: false
|
||||||
failed_when: false
|
failed_when: false
|
||||||
|
|
||||||
- name: "CASE A | DEV2 cancel pending reboot if found (kill reboot PIDs)"
|
- name: CASE A DEV2 cancel pending reboot if found
|
||||||
when: dhcp_migrated_ok | bool
|
when:
|
||||||
|
- dhcp_migrated_ok | bool
|
||||||
|
- (reboot_detect.stdout | trim) == "YES"
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
ansible.builtin.shell: |
|
ansible.builtin.shell: |
|
||||||
set -e
|
export DEV2_CMD="killall reboot 2>/dev/null || true"
|
||||||
# Extract PID from BusyBox ps output: assume PID is the first column.
|
{{ dev2_exec_cmd }}
|
||||||
# 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"
|
|
||||||
args: { executable: /bin/bash }
|
args: { executable: /bin/bash }
|
||||||
register: reboot_kill
|
|
||||||
changed_when: false
|
changed_when: false
|
||||||
failed_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
|
when: dhcp_migrated_ok | bool
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
cleanup_report: >-
|
case_a_report: >-
|
||||||
{{
|
{{ case_a_report
|
||||||
cleanup_report ~
|
~ '; pending reboot '
|
||||||
(
|
~ ((reboot_detect.stdout | trim) == 'YES'
|
||||||
('; pending reboot found, cancelled (pids=' ~ (reboot_kill.stdout | trim) ~ ')')
|
| ternary('found and cancelled', 'not found')) }}
|
||||||
if ((reboot_kill.stdout | default('') | trim) not in ['','NONE'])
|
|
||||||
else
|
|
||||||
'; no pending reboot found'
|
|
||||||
)
|
|
||||||
}}
|
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: CASE A | Final cumulative cleanup report
|
- name: CASE A final cumulative cleanup report
|
||||||
when: dhcp_migrated_ok | bool
|
when: dhcp_migrated_ok | bool
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg:
|
msg:
|
||||||
- "{{ cleanup_report }}"
|
- "{{ case_a_report }}"
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user