【发布时间】:2014-06-27 20:46:25
【问题描述】:
在我想要的厨师食谱中
- 解压文件
- 使用 zip 中的文件之一来迭代内容。
我遇到的问题是,当我运行 chef-client 时,它甚至在步骤 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也是
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
似乎 chef-client 在执行之前先遍历代码。所以在遍历文件中是不存在的,因为它在执行解压缩代码之前不会存在。
我怎样才能避免这种情况?
【问题讨论】:
-
您需要将该代码包装在
do_something_with_file中的ruby_block资源中。
标签: ruby chef-infra chef-recipe