为什么 Ansible 不能挂载 Vagrant 远程 NFS 共享 [英] Why won't Ansible mount Vagrant remote NFS share
问题描述
当我尝试执行挂载模块时,我的 Ansible playbook 出现错误:
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 (...)
流浪文件:
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 playbook 似乎存在一些问题.最后一部分不是有效的 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屋!