为什么Ansible无法挂载Vagrant远程NFS共享 [英] Why won't Ansible mount Vagrant remote NFS share
问题描述
当我尝试执行安装模块时,我的Ansible剧本出现了一个错误:
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
代码目录已安装:
$ vagrant ssh -c "mount | grep http"
192.168.33.1:/Users/me/playbooks/site1/website on /srv/http/site1.com type nfs (...)
Vagrantfile:
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剧本:
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
我正在运行NFS v3:
I'm running NFS v3:
$ sudo nfsstat | grep nfs # => Client nfs v3
我不确定为什么会这样.卸载任务将卸载文件系统,但以下装载任务失败. mount(8)手册页显示设备可能看起来像knuth.cwi.nl:/dir". nfs(5)手册页指出,服务器主机名可以是点分四组IPv4地址".我尝试将以下行添加到我的/etc/hosts文件中:
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
,然后将挂载名称参数"192.168.33.1"替换为"laptop",但这也没有解决.有人看到我在做什么错吗?
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?
谢谢.
推荐答案
您的Ansible剧本似乎有几个问题.最后一部分不是有效的YAML,但更重要的是,您的安装中的name
和src
被颠倒了.文档指出" src
是要挂载到名称上的设备".名称也应该是安装点的路径.这是解决了这些问题的剧本...
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
如果您进行了这些更改并注释了Vagrantfile中的synced_folder
,我认为它会以您想要的方式工作.
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.
这篇关于为什么Ansible无法挂载Vagrant远程NFS共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!