1
在厨师的食谱我想厨师:厨师,客户端首先散步代码执行它
- 之前解压文件
- 使用其中的一个文件中的zip遍历内容。
我遇到的问题是,当我运行厨师客户端失败说“没有这样的文件或目录”之前,它甚至解压缩在步骤1
这里的文件是提供商的代码:
action :create do
if @current_resource.exists
converge_by("Create #{ @current_resource }") do
unzip('realFileToUnzip','someLocation')
do_something_with_file('realFileToOpen')
end
end
end
....
在同一个供应商的文件我有一个高清的定义如下
def unzip(fileToUnzip, unzipToLocation)
bash "unzip" do
user "root"
cwd "/tmp"
code <<-EOH
unzip -o #{fileToUnzip} -d #{unzipToLocation}
EOH
end
end
,这也变形点焊
def do_something_with_file(fileToConvert)
::File.open(fileToConvert, 'r') do |properties_file|
properties_file.read.each_line do |line|
puts line
end
end
end
似乎厨师客户端在执行代码之前先行走代码。所以在遍历文件时不存在,因为它不会出现在执行解压缩代码之前。
我该如何避免这种情况?
您需要将该代码封装在'ruby_block'资源的'do_something_with_file'中。 – sethvargo