--- - name: Delay test hosts: mount become: false gather_facts: false vars: nfs_srv: zg-ds1.thezengarden.net nfs_mnt: /volume1/Testing nfs_path: /var/tmp/nfs_mnt tasks: - name: Mount something ansible.posix.mount: path: "{{ nfs_path }}" src: "{{ nfs_srv }}:{{ nfs_mnt }}" fstype: nfs state: ephemeral # - name: Remove rear backup entry from /etc/fstab if present # ansible.builtin.lineinfile: # path: /etc/fstab # regexp: '^.*\/var\/tmp\/nfs_mnt.*$' # state: absent # - name: Reboot host # ansible.builtin.reboot: - name: Pause ansible.builtin.pause: minutes: 10 # - name: Unmount something # ansible.posix.mount: # path: /var/tmp/nfs_mnt # state: absent - name: Try to unmount the filesystem block: - name: Unmount filesystem ansible.posix.mount: path: "{{ nfs_path }}" state: unmounted delay: 5 retries: 3 # - name: Fail # ansible.builtin.fail: # msg: Failed as requested from task rescue: - name: Kill processes using the filesystem ansible.builtin.command: cmd: "fuser -k {{ nfs_path }}" failed_when: false - name: Lazy unmount the NFS share ansible.builtin.command: cmd: "umount -l {{ nfs_path }}"