user60679
user60679

Reputation: 729

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

My Question is how can i create above file in append mode, next time this above resource run it should not override the content, but it should append it.

Upvotes: 0

Views: 222

Answers (1)

Tensibai
Tensibai

Reputation: 15784

Ok I'll do something 'simple' for the idea, a real oracle conf is too long for here.

Using attributes to define the DB (you may use a databag too)

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? %>

Here the master template will iterate over an attribute to render the DB.erb template inside itself with the properties passed.

The resulting file would be:

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

Hope it gives enought indication to use in your particular case

Upvotes: 1

Related Questions