我在LWRP中有以下代码,它所做的就是分解一个.ear文件:
action :expand do
ear_folder = new_resource.target_folder
temp_folder = "#{::File.join(ear_folder, 'tmp_folder')}"
expand_ear(new_resource.source, ear_folder)
expand_wars(ear_folder,temp_folder)
end
def expand_ear(src,dest)
bash "unzip EAR" do
cwd dest
code <<-EOF
pwd
ls -l
jar -xvf #{src}
EOF
end
end
def explode_wars(src,dest)
Dir.glob("#{basepath}/*.war") do |file|
......... ###crete tmp folder, move .war there then unzip it to 'dest'
end
end当我运行这个Chef Vagrant provide/时,输出显示/using并行地启动'expand_ear‘和'expand_wars’。因此,expand_wars定义无法找到仍在提取的所有.wars /they。我尝试将'expand_ear‘设置为布尔值,并将'expand_wars’包装在:
if expand_ear?(src,dest)
expand_war
end但这会产生相同的结果。?
发布于 2013-05-18 15:01:44
Chef run由编译和执行两个阶段组成。在第一阶段,厨师通过食谱和:
如果看到纯ruby代码,则执行
您的问题是,expand_ear中的代码会被编译-因为它是一种资源,而explode_wars中的代码会立即执行-因为它是纯ruby。有两种可能的解决方案:
更改您的expand_ear以动态定义bash资源:
res = Chef::Resource::Bash.new "unzip EAR", run_context
res.cwd dest
res.code <<-EOF
pwd
ls -l
jar -xvf #{src}
EOF
res.run_action :run这是纯ruby -因此将被执行而不是编译。
或将explode_wars中的ruby代码放入ruby_block资源中。
ruby_block do
block do
Dir.glob("#{basepath}/*.war") do |file|
......... ###crete tmp folder, move .war there then unzip it to 'dest'
end
end
end这样,它也将被编译,并仅在第二阶段执行。
https://stackoverflow.com/questions/16544534
复制相似问题