首页 > 解决方案 > 如何使用 ansible playbooks 卸载 NFS 文件系统

问题描述

我正在尝试使用 ansible 卸载 nfs 文件系统。我正在使用以下代码-

---
- name: first playbook
  hosts: localhost
  become: yes
  vars:
    path: "{{ path | mandatory }}"
  tasks:
        - name: unmount nfs
          mount:
             state: unmounted
             path: "path_of_nfs_filesystem"
          register: result
          
        - debug: 
             var=result.stdout

但是上面的代码并没有卸载。结果的输出是 "Variable is undefined" 。我也使用了单独的调试任务。我已根据最新更改修改了问题中的代码。请建议对我的代码进行一些更改。我对ansible剧本很陌生

标签: python-3.xansibleansible-inventoryansible-facts

解决方案


我发现这是我问题的解决方案。我希望这对其他人也有帮助

- name: Unmount a mounted volume
  mount:
    path: /tmp/mnt-pnt
    state: unmounted
  register: result
  retries: 5
  delay: 60
  until: result is not failed
- debug:
  var: result

重试和延迟是在挂载点忙且无法卸载时,在 60 秒的等待时间内最多重试 5 次


推荐阅读