1

I'm looking to add configurations to a conf file that is extracted from a tar file.

Currently the cookbook is using a template to overwrite the whole file instead I need to use the original file as a template and add to it.

Partial templates seem to do the task but I haven't been able to find an example of a partial being applied to an existing file,

is it even possible?

thank you

david
  • 741
  • 3
  • 10
  • 29
  • I might be able to give you a better answer if you can explain why you need to use the original file as a template vs. just using a standard chef template resource. – Tejay Cardon Jan 27 '15 at 16:42
  • the application is in a self-contained tar and all necessary files should and are in the tar, there must be no outside dependencies. Thus the application is delivered as a tar and not bundled with the cookbook. – david Jan 27 '15 at 16:48
  • Right, but in that case, you shouldn't need to modify the config file, right? If you need a config file different than what's in the tar, then the standard approach is to simply create a template in your cookbook that does this configuration. – Tejay Cardon Jan 27 '15 at 20:32

2 Answers2

1

No, you can't really do that. If the original isn't an erb template already, then you can't use it in this manner. You really have two choices.

  1. Create a template that includes the original file as a partial within it. I think this would work, though I've never tried it, and I'm not sure chef's system will let you use a file outside the cookbook as a partial.
  2. Use the FileUtil module from chef to modify the file in place. If you do that, I'd strongly suggest you create an LWRP to wrap it, and create the new file in the chef cache, then compare against the existing file, and only "update" if there is a change.

In reality, your best bet is almost certainly to just use a custom erb template for it. If there is some sort of special data in the original that you need to re-capture, you could use a ruby_block to read that data form the original and then pass it into your template.

Tejay Cardon
  • 4,193
  • 2
  • 16
  • 31
0

It appears you may use the second method. I have tried using partial template from this example but https://github.com/danielsdeleo/partials

  • Can you clarify your answer? It seems as though you have a partial sentence that might help if it was completed. (thx) – elbrant Mar 14 '19 at 02:15