From bda1e73e71b68d6b56da7093f44114f7a1fce8a7 Mon Sep 17 00:00:00 2001 From: Chris Hammer Date: Wed, 27 Aug 2025 13:33:09 -0400 Subject: [PATCH] Add hung NFS share management --- tasks/hung_nfs_check.yml | 38 ++++++++++++++++++++++++++++++++++++++ tasks/main.yml | 3 +++ 2 files changed, 41 insertions(+) create mode 100644 tasks/hung_nfs_check.yml diff --git a/tasks/hung_nfs_check.yml b/tasks/hung_nfs_check.yml new file mode 100644 index 0000000..5ce47d0 --- /dev/null +++ b/tasks/hung_nfs_check.yml @@ -0,0 +1,38 @@ +--- +- name: Check for mounted NFS shares # noqa: command-instead-of-module + ansible.builtin.command: mount -t nfs,nfs4 + register: lazy_reboot_nfs_mounts + changed_when: false + failed_when: lazy_reboot_nfs_mounts['rc'] not in [0, 32] + +- name: Create a list of NFS mount points + ansible.builtin.set_fact: + lazy_reboot_nfs_list: + "{{ lazy_reboot_nfs_mounts['stdout_lines'] | map('split') | map(attribute=2) | list }}" + +- name: Verify mount status and reboot host + block: + - name: Verify mount status + ansible.builtin.command: "ls {{ item }}" + timeout: 5 + changed_when: false + register: r_lazy_reboot_verify_mounts + loop: "{{ lazy_reboot_nfs_list }}" + loop_control: + label: "{{ item }}" + + rescue: + - name: Group shares that failed status check + ansible.builtin.set_fact: + lazy_reboot_failed_shares: + "{{ r_lazy_reboot_verify_mounts['results'] | selectattr('failed') | map(attribute='item') | list }}" + + - name: Lazily unmount the failed shares + ansible.builtin.command: "umount -f -l {{ item }}" + changed_when: false + register: r_lazy_unmount + async: 30 + poll: 0 + loop: "{{ lazy_reboot_failed_shares }}" + loop_control: + label: "{{ item }}" diff --git a/tasks/main.yml b/tasks/main.yml index ae320e4..82c5d9d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,4 +1,7 @@ --- +- name: Check for hung NFS mounts + ansible.builtin.include_tasks: hung_nfs_check.yml + - name: Capture initial boot ID ansible.builtin.slurp: src: "{{ verified_reboot_bootid_file }}"