Files
lazy_reboot/lazy_reboot.yml
Chris Hammer cbe905fb4c
All checks were successful
Ansible Code Pipeline / Ansible-Development-Pipeline (ansible-dev-fedora) (push) Successful in 9s
Refinements
2025-08-18 13:13:59 -04:00

53 lines
1.8 KiB
YAML

---
- name: Reboot host with hung NFS Share(s)
hosts: all
become: true
gather_facts: false
# With NFS share(s) being in a hung state, we cannot utilize `gather_facts`
# here as that too will hang -- We instead use command/set_fact to build
# the needed NFS mount list.
tasks:
- 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 }}"
always:
- name: Reboot host
ansible.builtin.include_role:
name: verified_reboot