I have 7 files and 1 war. I need to change values when I deploy them. I have this:
##usuario
#alfresco.user=*****
alfresco.user=********
##pass
#alfresco.password= sfsfs
alfresco.password=sfgsf
alfresco.rutaAnexos=/gthtfdh/dfgdf/cm:
#atributo.type.anexo=ANEXO_INFO_OBJETO
atributo.type.anexo=AN
atributo.type.observaciones=OBSERVACIONES
I need to comment some lines and uncomment some other lines. Then I need to make seven templates and put variables depending on the environments and create a file in the recipe.
How can I do this?
Here is an example of how you can use Chef to uncomment a line in a configuration file. The
ruby_block
is protected with a::File::grep
. The test for Debian is just for fun.Chef actually allows and uses this. You can find an example in the opscode's
cookbooks/chef-server/recipes/default.rb
:Here's the use-case. After the installation from source I had to uncomment lines in some created configuration file that hadn't been the same in all versions of software, therefore use of templates hadn't been appropriate. The methods I used were:
You may find the full documentation here:
TO STRESS: This method is to be used only when using templates and partials is inappropriate. As @StephenKing already said, templates are common way of doing this.
By design, you don't modify files with Chef. Instead you put placeholders (
<%= ..%>
) into the file templates, which are then replaced with the dynamic values (so called attributes).