Using Chef to edit app.config and web.config during a run

I’ve run into an issue with our Chef automation where i’ve found it extremely tricky to update app/web.config files, so i’ve put together the dotnetconfig cookbook to take care of this.

Code available here: https://github.com/jerseyfoxcom/dotnetconfig

Installing

To use it, first download it from the Chef supermarket and unzip it to your cookbooks folder :-

knife supermarket download dotnetconfig --file dotnetconfig.tar.gz
tar -zxvf dotnetconfig.tar.gz

(you will also need to do this with nokogiri, on which it is dependent)

Use it within your own cookbooks by adding the following line to your cookbook’s metadata.rb.

depends         'dotnetconfig'

Within a recipe, add the following lines to include the recipe and import the DotNetConfig module.

include_recipe 'dotnetconfig'
::Chef::Recipe.send(:include, DotNetConfig)

Using the library

config_set_app_setting(document, 'fix-gateways', 'Replaced')
config_set_connection_string(document, 'Database1', 'Database=Partial;User Id=Replacement;Password=PasswordChanged;CommandTimeout=30;MinPoolSize=0')

Full usage instructions are available here.