Files
quick_test/nfs_lazy_reboot3.yml
2025-07-30 16:54:19 -04:00

47 lines
1.5 KiB
YAML

---
- name: Reboot host with hung NFS Share(s)
hosts: temp
become: true
gather_facts: false
# With NFS share(s) being in a hung state, we cannot utilize `gather_facts`
# as that too hangs when it tries to figure out the current mounts on the
# system
tasks:
- name: Check for mounted NFS shares # noqa: command-instead-of-module
ansible.builtin.command: mount -t nfs,nfs4
register: nfs_mounts_result
changed_when: false
failed_when: nfs_mounts_result['rc'] not in [0, 32]
- name: Create a list of NFS mount points from command output
ansible.builtin.set_fact:
nfs_mount_list: "{{ nfs_mounts_result['stdout_lines'] | map('split') | map(attribute=2) | list }}"
- name: Verify mount status
ansible.builtin.command: "ls {{ item }}"
timeout: 5
register: r_verify_mounts
ignore_errors: true
loop: "{{ nfs_mount_list }}"
loop_control:
label: "{{ item }}"
- name: Group failed shares together
ansible.builtin.set_fact:
failed_nfs_shares:
"{{ r_verify_mounts['results'] | selectattr('failed') | map(attribute='item') | list }}"
- name: Lazily unmount failed shares
ansible.builtin.command: "umount -f -l {{ item }}"
async: 30
poll: 0
register: r_lazy_unmount
loop: "{{ failed_nfs_shares }}"
loop_control:
label: "{{ item }}"
- name: Reboot host # noqa: no-handler
ansible.builtin.import_role:
name: verified_reboot