Chef 10: How to use remote_file or similar to get a file from a Windows share?

∥☆過路亽.° 提交于 2019-12-13 02:57:23

问题


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

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