Add a few things; nfs_lazy_reboot2.yml/nfs_lazy_reboot3.yml are valid; v2 is best POC
This commit is contained in:
44
nfs_lazy_reboot.yml
Normal file
44
nfs_lazy_reboot.yml
Normal file
@ -0,0 +1,44 @@
|
||||
---
|
||||
- name: Something
|
||||
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
|
Reference in New Issue
Block a user