45 lines
1.4 KiB
YAML
45 lines
1.4 KiB
YAML
---
|
|
- name: Reboot host with hung NFS Share(s)
|
|
hosts: temp
|
|
become: true
|
|
gather_facts: true
|
|
|
|
# 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: Capture NFS mounts on host
|
|
ansible.builtin.set_fact:
|
|
captured_nfs_mounts: "{{ ansible_mounts | selectattr('fstype', 'search', 'nfs') }}"
|
|
|
|
- name: Verify mount status and reboot
|
|
block:
|
|
- name: Verify mount status
|
|
ansible.builtin.command: "ls {{ item['mount'] }}"
|
|
timeout: 5
|
|
register: r_verify_mounts
|
|
loop: "{{ captured_nfs_mounts }}"
|
|
loop_control:
|
|
label: "{{ item['mount'] }}"
|
|
|
|
rescue:
|
|
- name: Debug item
|
|
ansible.builtin.debug:
|
|
msg: "{{ r_verify_mounts }}"
|
|
|
|
- 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['mount'] }}"
|
|
loop: "{{ __failed_nfs_shares }}"
|
|
loop_control:
|
|
label: "{{ item['mount'] }}"
|
|
|
|
always:
|
|
- name: Reboot host # noqa: no-handler
|
|
ansible.builtin.import_role:
|
|
name: verified_reboot
|