Chef infra 厨师长LWRP-defs/资源执行令
我在LWRP中有以下内容,它所做的只是爆炸一个.ear文件:Chef infra 厨师长LWRP-defs/资源执行令,chef-infra,vagrant,Chef Infra,Vagrant,我在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 d
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
但这会产生相同的结果。编译和执行分为两个阶段。在第一阶段中,厨师会浏览菜谱并:
expand\u ear
中的代码会被编译,因为它是一种资源,而explode\u wars
中的代码会被直接执行,因为它是纯ruby。有两种可能的解决方案:
更改扩展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
这样它也将被编译,并且只在第二阶段执行
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_block do
block do
Dir.glob("#{basepath}/*.war") do |file|
......... ###crete tmp folder, move .war there then unzip it to 'dest'
end
end
end