使用Windows共享在linux中的remote_file

时间:2015-11-25 11:42:49

标签: linux chef chef-recipe windows-share

我正在尝试使用Windows共享来复制文件。它在windows中运行良好,因为当我使用它时它会出错。

remote_file 'download' do 
source 'file:////server/repo/client.zip' 
path "/etc/chef/client.zip" 
end

错误日志

Errno :: ENOENT ------------- 没有这样的文件或目录@ rb_sysopen - /server/repo/client.zip

Resource Declaration: --------------------- 
# In 52: remote_file 'download' do 
53: source 'file:////server/repo/client.zip' 
54: path "/etc/chef/client.zip" 
56: end 
57: #end

2 个答案:

答案 0 :(得分:1)

这在UNC路径上完全有效的事实是偶然的(尽管任何人都采取错误的方式,它不会被移除AFAIK)。 Linux没有类似的模式。您可以使用execute资源和cp来涵盖基本用例。

execute 'cp /from /to' do
  creates '/to'
end

答案 1 :(得分:0)

你可以尝试:

remote_file 'download' do 
  source '\\server\repo\client.zip' 
  path "/etc/chef/client.zip" 
end

remote_file资源通过Chef::Provider::RemoteFile::NetworkFile类支持Windows网络路径(如果有人想在源代码中挖掘更多信息)。

remote_file下的调度程序关闭了前导的双重回扫'\\',因此这些字符必须是回溯而不是正斜杠。另请注意,我使用的是单引号而不是双引号 - 如果使用双引号(用于插值或只是样式),则需要自行转义回溯,它变为source "\\\\server\\repo\\client.zip"。我相当确定ruby本身会容忍其余的后备线被改为正斜线(所以source '\\server/repo/client.zip'可能是合法的吗?),但这看起来很尴尬。

此功能首先在https://github.com/chef/chef/pull/3336

中的12.4.0中发布
相关问题