在 Chef 中如何以追加模式创建模板

In Chef how to Create a template in append mode

template "/etc/myfile.log" do
  source "myfile.log"
  owner root
  group root
  mode 644
end

我的问题是如何在追加模式下创建上述文件,下次上述资源 运行 它不应该覆盖内容,但应该追加它。

好的,我会为这个想法做点什么'simple',真正的 oracle conf 在这里太长了。

使用属性定义数据库(你也可以使用数据包)

Attribute.rb

default['databases']['first']['codepage'] = "utf8"
default['databases']['first']['basedir'] = "/var/data/db1"
default['databases']['second']['codepage'] = "utf8"
default['databases']['second']['basedir'] = "/var/data/db2"

DB.erb

#Section <%= @dbname %>
  <%= @dbname %>.codepage = "<%= @props['codepage'] %>"
  <%= @dbname %>.path     = "<%= @props['basedir'] %>"
#End of section for <%= @dbname %>

Master.erb

#Any configuration needing to be there as common
default.codepage = "cp1252"
default.path     = "/var/data/default"

<%- node['databases'].each do |db,properties|
  <%= render "DB.erb", :variables => {:dbname => db, :props => properties } %>

<%- end.unless node['databases'].nil? %>

此处主模板将迭代一个属性,以在其内部呈现 DB.erb 模板并传递属性。

生成的文件将是:

default.codepage = "cp1252"
default.path     = "/var/data/default"

#Section first
  first.codepage = "utf8"
  first.path     = "/var/data/db2"
#End of section for first

#Section second
  second.codepage = "utf8"
  second.path     = "/var/data/db2"
#End of section for second

希望它能提供足够的指示以供您在特定情况下使用