为什么 Ansible 不能挂载 Vagrant 远程 NFS 共享

Why won't Ansible mount Vagrant remote NFS share

当我尝试执行挂载模块时,我的 Ansible 剧本出现错误:

Error mounting 192.168.33.1:/Users/me/playbooks/site1/website: mount.nfs: remote share not in 'host:dir' format

挂载代码目录:

$ vagrant ssh -c "mount | grep http"
192.168.33.1:/Users/me/playbooks/site1/website on /srv/http/site1.com type nfs (...)

流浪文件:

Vagrant.configure("2") do |config|
  config.vm.box = "debian/jessie64"
  config.vm.network "forwarded_port", guest: 80, host: 8080
  config.vm.network "forwarded_port", guest: 443, host: 8443
  config.vm.network "private_network", ip: "192.168.33.10"
  config.vm.synced_folder "website/", "/srv/http/site1.com", nfs: true
end

Ansible 剧本:

- name: Remount code directory
  hosts: web
  sudo: True
  tasks:
    - name: unmount website
      mount:
        name: /srv/http/site1.com
        src: srv_http_site1.com
        fstype: nfs
        state: unmounted
    - name: remount website
      mount: 
        name="192.168.33.1:/Users/me/playbooks/site1/website"
        src="srv_http_site1.com" 
        fstype=nfs 
        state=mounted

我是 运行 NFS v3:

$ sudo nfsstat | grep nfs  # => Client nfs v3

我不确定为什么会这样。卸载任务将卸载文件系统,但以下装载任务失败。 mount(8) 手册页说 "device may look like knuth.cwi.nl:/dir"。 nfs(5) 手册页说服务器主机名可以是 "a dotted quad IPv4 address"。我尝试将以下行添加到我的 /etc/hosts 文件中:

laptop    192.168.33.1

然后用 "laptop" 替换挂载名称参数“192.168.33.1”,但这也没有解决问题。有人看到我做错了什么吗?

谢谢。

您的 Ansible 剧本似乎有几个问题。最后一部分不是有效的 YAML,但更重要的是,您的装载中的 namesrc 被颠倒了。文档指出“src is device to be mounted on name”。名称也应该是挂载点的路径。这是解决了这些问题的剧本...

- name: Remount code directory
  hosts: web
  sudo: True
  tasks:
    - name: unmount website
      mount:
        name: /srv/http/site1.com
        src: 192.168.33.1:/Users/me/playbooks/site1/website
        fstype: nfs
        state: unmounted
    - name: remount website
      mount:
        name: /srv/http/site1.com
        src: 192.168.33.1:/Users/me/playbooks/site1/website
        fstype: nfs
        state: mounted

如果您进行这些更改并注释掉 Vagrantfile 中的 synced_folder,我认为它会按照您想要的方式工作。