Chef newbie: Web.config manipulations

Hi,

Just wondering if there is any tutorial out there that goes through modifying Windows .net .config files using Chef whereby the config file is tokenised in the following way:

I want a range of tokens which are unique across the different environments and can be used across apps, and the system will replace the relevant values with the actual values. I have used DSC XTokenize module to do similar in the past, but I want to see if I can do it in Chef, possibly using data bags to store the information.

Like I say I feel I am possibly missing something as there must be a tutorial on it somewhere but not found anything specific, hopefully you guys can prove me wrong!

Thanks,
Andrew.

Le 2015-09-22 17:27, Andrew Hodgson a écrit :

Hi,

Just wondering if there is any tutorial out there that goes through modifying Windows .net .config files using Chef whereby the config file is tokenised in the following way:

I want a range of tokens which are unique across the different environments and can be used across apps, and the system will replace the relevant values with the actual values. I have used DSC XTokenize module to do similar in the past, but I want to see if I can do it in Chef, possibly using data bags to store the information.

Like I say I feel I am possibly missing something as there must be a tutorial on it somewhere but not found anything specific, hopefully you guys can prove me wrong!

Thanks,
Andrew.

If they are standard text files, templates[1] are the way to go, I
would set the attributes in a chef-vault[2] (to keep the password
encrypted on the chef-server side) and named the databag item per the
environment.

This need some documented steps to load the databag item and pass it to
the template resource to render the file according to your needs.Maybe
the dsc_resource[3] or dsc_script[4] could be a way to go too, but as
I’m not using them I can’t really tell.

[1] https://docs.chef.io/resource_template.html [1]

[2] https://github.com/Nordstrom/chef-vault [2]

[3] https://docs.chef.io/resource_dsc_resource.html

[4] https://docs.chef.io/resource_dsc_script.html

Hope this helps.

Links:

[1] https://docs.chef.io/resource_template.html
[2] https://github.com/Nordstrom/chef-vault

Tensibai wrote:

Le 2015-09-22 17:27, Andrew Hodgson a écrit :

Hi,

Just wondering if there is any tutorial out there that goes through modifying Windows .net .config files using Chef whereby the config file is tokenised in the following way:

I want a range of tokens which are unique across the different environments and can be used across apps, and the system will replace the relevant values with the actual values. I have used DSC XTokenize module to do similar in the past, but I >>want to see if I can do it in Chef, possibly using data bags to store the information.

[…]

If they are standard text files, templates[1] are the way to go, I would set the attributes in a chef-vault[2] (to keep the password encrypted on the chef-server side) and named the databag item per the environment.

I did look into templates quite a bit, but wanted a more simple token replacement strategy rather than relying on a more complex Erubis structure. I went back to using DSC tokenization in the end using the xTokenize module.

Thanks for confirming I was looking in the right direction though.

Best.
Andrew.

Le 2015-09-23 12:09, Andrew Hodgson a écrit :

Tensibai wrote:

Le 2015-09-22 17:27, Andrew Hodgson a écrit :
Hi,

Just wondering if there is any tutorial out there that goes through modifying Windows .net .config files using Chef whereby the config file is tokenised in the following way:

I want a range of tokens which are unique across the different environments and can be used across apps, and the system will replace the relevant values with the actual values. I have used DSC XTokenize module to do similar in the past, but I >>want to see if I can do it in Chef, possibly using data bags to store the information.

[…]

If they are standard text files, templates[1] are the way to go, I would set the attributes in a chef-vault[2] (to keep the password encrypted on the chef-server side) and named the databag item per the environment.

I did look into templates quite a bit, but wanted a more simple token
replacement strategy rather than relying on a more complex Erubis
structure. I went back to using DSC tokenization in the end using the
xTokenize module.

Thanks for confirming I was looking in the right direction though.

This one (with no clue from where comes the tokens… so hard to really
compare)

Vs a template named Web.config.erb

For a template resource being:

template “path/to/Web.config” do
source "Web.config.erb"
variables( :params => data_bag_item(‘AppSqlInfo’,node.chef_environment
)
end

And a databag ‘AppSqlInfo’ with an item for each environment containing
a hash like this:

{ :AppDBServer => “Server”,
:AppDatabase => “DbName”,
:AppDBUserId => “User”,
:AppDBPassword => "password
}

What do you find complex there ?
From my window the templates structure is nearly the same (<%= var %>
instead of var), and according to the doc I read on xTokenize,
you’ll have to build the hash file or to distribute one according to the
environment too…

I would really like to get your feedback on what you find more complex
in this approach than the xTokenize one

Hi Andrew, I do quite a bit of .asp.Net and .net deployments with chef and so far I usually start from a template file made the original config file.

HTH