【问题标题】:Writing file with multiple Chef cookbooks all targeting the same file使用多个针对同一文件的 Chef 食谱编写文件
【发布时间】:2015-09-04 16:23:05
【问题描述】:

我有三本食谱,每本都有一个写入 /etc/hosts 文件的模板资源。

我想追加而不是覆盖:

  • 第一本说明书创建 /etc/hosts 文件并写入第 1、2、3 行。
  • 第二本食谱附加了第 4,5 行。等

在 Chef Land 中处理此问题的正确方法是什么?

【问题讨论】:

标签: ruby chef-infra cookbook


【解决方案1】:

您最好创建一个食谱来管理从属性生成的文件。

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"

使用&lt;&lt; 附加到属性而不是覆盖它们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-25
    • 1970-01-01
    • 1970-01-01
    • 2017-07-11
    • 2015-09-17
    • 2014-11-06
    • 1970-01-01
    • 2023-04-05
    相关资源
    最近更新 更多