Igor Zilberman
Igor Zilberman

Reputation: 1208

Modify configuration files with Chef

I am writing a cookbook to install and configure an application. From what I googled, the best way to modify configuration, is to put a template of that config file. But an app can have different versions and config files may vary. What is the best solution here? Create a provider and a resource that will modify files in-place or create a ruby blocks that will handle the change? Thanks.

Upvotes: 0

Views: 1860

Answers (2)

Tensibai
Tensibai

Reputation: 15784

What we do is syncing the app cookbook version to app version.

This cookbook is responsible to deploy the app and configure it, so the template is updated accordingly when version change.

You don't give much information on what change there could be in the configuration file, usually the best bet is to have an exhaustive config and enabling or not parts of it based on attributes values to tweak it on the desired stated according to environment, role, version and so on.

follow-up answer on the follow-up question

Upvotes: 1

sjn
sjn

Reputation: 181

I am assuming you have a config file which is XML or JSON or something similar and there are configuration parameters and respective values.

If by config file variation you meant config parameter value variation then you can use ERB Template for creating a config template. As you create template you add variables for the changing config values. These variables are determined during the runtime and the variables values are provided in your recipe.

The configuration parameter/template itself could be changing with different versions of the application. In my experience, one way to handle that is to couple cookbook version to your application version. That way you can update the config template as the application evolves.

Upvotes: 0

Related Questions