I have a template file in my chef cookbook named 'Test Template', In my Chef recipe I am sourcing and updating my template file to a file '/etc/run/mn.txt' as follows:
template 'Test Template' do
source 'run.config'
path /etc/run/mn.txt
end
I need to update this template file dynamically during the chef run before the above "template" resource is called. How can I edit the template file itself within my cookbook before the template resource is called? I need to do this because there are lines I am adding to the template file and if I add the lines afterward to the created file after this resource block, it will just get reverted back to the original template contents during the next chef-client run.
Do you know the contents that you want to include in
/etc/run/mn.txtbefore the template resource is executed? If so, you can use the variables property (A Hash of variables that are passed into a Ruby template file) to push the contents into the/etc/run/mn.txtfile:And then in your run.config, you could add to the end something like:
(Or you could pass the variables parameter a hash, and do some sort of loop through the hash keys in your template.. to make it more dynamic)