Why won't Ansible mount Vagrant remote NFS share

混江龙づ霸主 提交于 2019-12-23 03:08:31

问题


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:


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.



来源:https://stackoverflow.com/questions/34786368/why-wont-ansible-mount-vagrant-remote-nfs-share

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!