[英]Merge attributes from different Chef cookbooks or recipes
是否可以合並多個食譜或食譜中的屬性?
我要實現以下目標:
食譜1
設置默認屬性列表,例如default [:bamboo] [:agent] [:attributes] = {'system.attr-1'=>'test1'}
在template.conf中 ,我有
<% if @options -%>
<% @options.sort.map do | option, value | -%>
<%= option %>= <%= value %>
<% end -%>
<% end -%>
食譜2
固有的“食譜1”並有2個食譜
RECIPE1
node.default[:bamboo][:agent][:attributes] = {
'system.attr-2' => 'test2'
}
recipe2
node.default[:bamboo][:agent][:attributes] = {
'system.attr-3' => 'test3'
}
現在,我想要的是將“ cookbook 1”中的template.conf更新/合並為cookbook2的屬性以及這些食譜。
這可能嗎? 如果沒有,還有哪些其他選擇?
在食譜2中,您想利用Ruby的Hash#merge
:
node.default[:bamboo][:agent][:attributes] = node[:bamboo][:agent][:attributes].merge(
'system.attr-3' => 'test3'
)
然后確保菜譜2依賴於菜譜1(因此首先加載屬性)。
不知道這是否是最美麗的方式,但是可以使用
node.default[:bamboo][:agent][:attributes] = node[:bamboo][:agent][:attributes].merge(
'system.attr-3' => 'test3'
)
template 'bamboo-capabilities.properties' do
path "#{node[:bamboo][:agent][:data_dir]}/bin/bamboocapabilities.properties"
source 'bamboo-capabilities.properties.erb'
cookbook 'bamboo'
owner node[:bamboo][:agent][:user]
group node[:bamboo][:agent][:group]
mode 0644
variables(
:options => node[:bamboo][:agent][:attributes]
)
notifies :restart, 'service[bamboo-agent]', :delayed
end
編輯::好的,這確實會造成一些問題,因為cookbook1很想刪除舊條目,並且當它最終到達cookbook2配方1時,它將再次添加條目,這會在每次廚師運行時重新啟動
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.