Chef 10:如何使用remote_file或类似方法从Windows共享中获取文件? [英] Chef 10: How to use remote_file or similar to get a file from a Windows share?

查看:142
本文介绍了Chef 10:如何使用remote_file或类似方法从Windows共享中获取文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 remote_file 在Windows共享上缓存大型软件包的本地副本。如何完成?

I'm trying to use remote_file to cache a local copy of a large package on a Windows share. How is this done?

我无法使其与基于驱动器字母的路径,基于UNC的路径或文件: URL。

I can't get it to work with a drive-letter-based path, a UNC-based path, or a file: URL.

推荐答案

我制定了一个技巧,我认为它很简洁。我创建了以下定义(并将其放在 definitions / default.rb 中):

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

定义的工作方式与资源不同,但这很容易实现,并且可以满足我的需要。当然,通过内存读取无法对大文件进行操作,但是它允许Chef在触发对文件资源的操作之前检查内容是否不同。

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.

这篇关于Chef 10:如何使用remote_file或类似方法从Windows共享中获取文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆