首页 > 解决方案 > 为什么我的 nfs4 挂载不能与 ansible 一起使用?

问题描述

使用 Ansible,我无法挂载 nfs4。

我在服务器上配置了 nfs4 导出,我可以使用 bash shell 安装 nfs4 和 nfs。

我也可以让 nfs 在 ansible 中工作,而不是在 nfs4 中工作。

所以我想知道如何将服务器上的 /pool1/volume1 之类的共享安装到客户端上的相同样式路径- /pool1/volume1

尝试切换到有效的标准 nfs,我可以在 bash shell 中安装 nfs4,但不能使用 ansible

这有效-

  - name: mount softnas NFS volume
    become: yes
    mount:
      fstype: nfs
      path: "/pool1/volume1"
      opts: rsize=8192,wsize=8192,timeo=14,intr,_netdev
      src: "10.0.11.11:/pool1/volume1"
      state: mounted

但这并不

  - name: mount softnas NFS volume
    become: yes
    mount:
      fstype: nfs4
      path: "/pool1/volume1"
      opts: rsize=8192,wsize=8192,timeo=14,intr,_netdev
      src: "10.0.11.11:/pool1/volume1"
      state: mounted

如果我在 shell 中使用这个命令,这在将路径安装到测试中效果很好。sudo mount -t nfs4 10.0.11.11:/ /test 虽然它不太正确,因为像 /pool1/volume1 和 /pool2/volume2 这样的 id 不会出现在 /test 下

我在服务器上的导出文件是这个-

/ *(ro,fsid=0)
# These mounts are managed in ansible playbook softnas-ebs-disk-update-exports.yaml
# BEGIN ANSIBLE MANAGED BLOCK /pool1/volume1/
/pool1/volume1/ *(async,insecure,no_subtree_check,no_root_squash,rw,nohide)
# END ANSIBLE MANAGED BLOCK /pool1/volume1/
# BEGIN ANSIBLE MANAGED BLOCK /pool2/volume2/
/pool2/volume2/ *(async,insecure,no_subtree_check,no_root_squash,rw,nohide)
# END ANSIBLE MANAGED BLOCK /pool2/volume2/

当我尝试切换到 nfs4 时,我用 ansible 收到此错误

安装 /pool1/volume1/ 时出错:mount.nfs4:安装 10.0.11.11:/pool1/volume1/ 失败,服务器给出的原因:没有这样的文件或目录

标签: ansible

解决方案


检查挂载点是否存在

mkdir /pool1/volume1 # if not exists. Or create an ansible task to create the directory

更新为随着份额的变化而变化 /

  - name: mount softnas NFS volume
    become: yes
    mount:
      fstype: nfs4
      path: "/pool1/volume1"
      opts: rsize=8192,wsize=8192,timeo=14,intr,_netdev
      src: "10.0.11.11:/"
      state: mounted

如果不想挂载/,则在服务器中共享/pool1/volume1。


推荐阅读