【发布时间】:2015-09-04 16:23:05
【问题描述】:
我有三本食谱,每本都有一个写入 /etc/hosts 文件的模板资源。
我想追加而不是覆盖:
- 第一本说明书创建 /etc/hosts 文件并写入第 1、2、3 行。
- 第二本食谱附加了第 4,5 行。等
在 Chef Land 中处理此问题的正确方法是什么?
【问题讨论】:
标签: ruby chef-infra cookbook
我有三本食谱,每本都有一个写入 /etc/hosts 文件的模板资源。
我想追加而不是覆盖:
在 Chef Land 中处理此问题的正确方法是什么?
【问题讨论】:
标签: ruby chef-infra cookbook
您最好创建一个食谱来管理从属性生成的文件。
CookbookA/attributes/default.rb
default['hosts']['lines'] = []
CookbookA/recipes/genfile.rb
template "/etc/hosts" do
source "hosts.erb"
end
CookbookA/templates/default/hosts.erb
#File Generated by Chef
<% node['hosts']['lines'].each do |l| %>
<% l -%>
<% end.unless node['hosts']['lines'].empty? %>
然后在您的其他食谱属性文件中:
default['hosts']['lines'] << ["first line","second line"]
拥有这些食谱取决于 CookbookA 和他们的食谱电话 include_recipe "CookbookA::genfile.rb"
使用<< 附加到属性而不是覆盖它们。
【讨论】: