问题
I'm trying to use remote_file
to cache a local copy of a large package on a Windows share. How is this done?
I can't get it to work with a drive-letter-based path, a UNC-based path, or a file:
URL.
回答1:
Don't have windows to test, but something like this should work:
require 'fileutils'
remote_path = '...'
local_path = '...'
ruby "cache-#{remote_path}" do
block { FileUtils.copy_file(remote_path, local_path) }
not_if { File.exists?(local_path) }
end
回答2:
I worked out a trick that I think is pretty neat. I created the following definition (and put it in definitions/default.rb
):
define :file_from_network, :action => :create do
myPath = (params[:path] || params[:name])
mySource = params[:source]
if File.exist?(mySource)
file myPath do
action params[:action]
content File.open(mySource) {|io| io.read}
end
else
Chef::Log.error("File #{mySource} not found!")
end
end
Definitions do not work quite the same way resources do, but this was easy to implement and does what I need it to do. The in-memory read makes it impractical for huge files, of course, but it allows Chef to check that the content is different before triggering an action on the file resource.
来源:https://stackoverflow.com/questions/14409881/chef-10-how-to-use-remote-file-or-similar-to-get-a-file-from-a-windows-share