Why won't Ansible mount Vagrant remote NFS sha

2019-06-07 22:23发布

My Ansible playbook is raising an error when I try to execute the mount module:

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

The code directory is mounted:

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

Vagrantfile:

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 playbook:

- 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

I'm running NFS v3:

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

I'm not sure why this is happening. The unmount task will unmount the filesystem but the following mount tasks fails. The mount(8) man page says "device may look like knuth.cwi.nl:/dir". The nfs(5) man page says that server host names can be "a dotted quad IPv4 address". I tried adding the following line to my /etc/hosts file:

laptop    192.168.33.1

and then replacing the mount name argument "192.168.33.1" with "laptop" but that didn't fix it either. Does anyone see what I'm doing wrong?

Thanks.

1条回答
Fickle 薄情
2楼-- · 2019-06-07 22:53

You seem to have a couple of issues with your Ansible playbook. The last part is not valid YAML, but more importantly the name and src in your mounts are reversed. The docs state that "src is device to be mounted on name". Also the name should be the path to the mount point. Here's the playbook with those issues resolved...

- 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

If you make these changes and comment out the synced_folder in your Vagrantfile, I think it will work in the way that you want.

查看更多
登录 后发表回答