# Re: Re: Re: Dynamic Template File

**URL:** <https://discourse.chef.io/t/re-re-re-dynamic-template-file/2813>\
**Category:** Chef Infra (archive)\
**Created:** [May 8, 2012, 12:22pm UTC](https://discourse.chef.io/t/re-re-re-dynamic-template-file/2813 "2012-05-08T12:22:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Soula\_William](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@Soula\_William](https://discourse.chef.io/u/Soula_William)\
**Post date:** [May 8, 2012, 12:22pm UTC](https://discourse.chef.io/t/re-re-re-dynamic-template-file/2813/1 "2012-05-08T12:22:05Z")

</div>

base\_install\_path=node[‘mobi.GIS’][‘install’][‘install\_path’]  
installer\_install\_path=File.join(base\_install\_path,“installer”)  
installer\_config\_properties\_file = File.join(installer\_install\_path,“mobi.GIS-install-config.properties”)  
template installer\_config\_properties\_file do  
source "mobi.GIS-config-ant-properties.erb"  
variables(  
:config =\> node[‘mobi.integration’][‘config’]  
)  
end

## [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] INFO: template[c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties] backed up to c:/chef/backup/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties.chef-20120507111115 [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] ERROR: template[c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties] (mobi.GIS::default line /chef/cache/cookbooks/mobi.GIS/recipes/default.rb) has had an error [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] ERROR: template[c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties] (c:/chef/cache/cookbooks/mobi.GIS/recipes/default.rb:12:in `from_file') had an error: tsomerville.pointserve.com template[c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties] (mobi.GIS::default line /chef/cache/cookbooks/mobi.GIS/recipes/default.rb) had an error: Errno::EACCES: Permission denied - c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1314:in`unlink’[tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1314:in `block in remove_file' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1322:in`platform\_support’ [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1313:in `remove_file' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:511:in`block in mv’ [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1423:in `block in fu_each_src_dest' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1439:in`fu\_each\_src\_dest0’ [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1421:in `fu_each_src_dest' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:504:in`mv’ [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/provider/template.rb:47:in `block in action_create' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/mixin/template.rb:48:in`block in render\_template’ [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/1.9.1/tempfile.rb:320:in `open' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/mixin/template.rb:45:in`render\_template’ [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/provider/template.rb:99:in `render_with_context' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/provider/template.rb:39:in`action\_create’ [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource.rb:440:in `run_action' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/runner.rb:45:in`run\_action’ [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/runner.rb:81:in `block (2 levels) in converge' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/runner.rb:81:in`each’ [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/runner.rb:81:in `block in converge' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource_collection.rb:94:in`block in execute\_each\_resource’ [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource\_collection/stepable\_iterator.rb:116:in `call' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource_collection/stepable_iterator.rb:116:in`call\_iterator\_block’ [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource\_collection/stepable\_iterator.rb:85:in `step' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource_collection/stepable_iterator.rb:104:in`iterate’ [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource\_collection/stepable\_iterator.rb:55:in `each_with_index' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource_collection.rb:92:in`execute\_each\_resource’ [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/runner.rb:76:in `converge' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/client.rb:312:in`converge’ [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/client.rb:160:in `run' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/application/client.rb:239:in`block in run\_application’ [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/application/client.rb:229:in `loop' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/application/client.rb:229:in`run\_application’ [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/application.rb:67:in `run' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/bin/chef-client:26:in`\<top (required)\>' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/bin/chef-client:19:in `load' tsomerville.pointserve.com C:/opscode/chef/bin/chef-client:19:in`' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] ERROR: Running exception handlers [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] FATAL: Saving node information to c:/chef/cache/failed-run-data.json [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] ERROR: Exception handlers complete [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] FATAL: Errno::EACCES: template[c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties] (mobi.GIS::default line /chef/cache/cookbooks/mobi.GIS/recipes/default.rb) had an error: Errno::EACCES: Permission denied - c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties

Could you show the code for the recipe or at least the template resource which is creating the file? Can you also give the stacktrace to the permission denied error?

The permission denied error makes me think something is wrong with the chef installation or you are using chef incorrectly.

You should be able to do something like,

template “/path/to/my.properties” do  
variables(  
:config =\> node[:myEnvironmentConfig]  
)  
end

## On Mon, May 7, 2012 at 3:50 PM, Soula, William \<[wsoula@mobicorp.com](mailto:wsoula@mobicorp.com)[mailto:wsoula@mobicorp.com](mailto:wsoula@mobicorp.com)\> wrote: I guess I can just not use templates and output a file with ruby that contains the values I want and that way I don’t have to worry about chef funkiness.

My environment file has a config section with name, value pairs in it. I am trying to output a template of those name, value pairs by putting the below code into my erb file in chef:  
\<% @config.each do |setting| -%\>  
\<%= setting[0] %\>=\<%= setting[1] %\>  
\<%end-%\>

This works great the first time as it creates a property file with my name value pairs.

The problem is when the config section changes. I get a Permission denied error, but if I rerun the recipe then everything works and the new value is in the property file.

How can I create dynamic property files from the environment json file?

Thanks,  
Will

–  
-Bryan

---

<div class="post-metadata">

**Author:** ![bbaugher](https://avatars.discourse-cdn.com/v4/letter/b/97f17d/32.png) [@bbaugher](https://discourse.chef.io/u/bbaugher)\
**Post date:** [May 8, 2012, 3:12pm UTC](https://discourse.chef.io/t/re-re-re-dynamic-template-file/2813/2 "2012-05-08T15:12:18Z")

</div>

Ugh, windows. Fortunately I have not had the chance to even try chef  
cookbooks on windows.

I know that chef 0.10.6 [1] was supposed to have large improvements for  
windows that could solve your problem. Otherwise I have no idea what the  
problem could be.

[1] -  
[http://wiki.opscode.com/display/chef/Release+Notes#ReleaseNotes-ReleaseNotesChefVersion0.10.6](http://wiki.opscode.com/display/chef/Release+Notes#ReleaseNotes-ReleaseNotesChefVersion0.10.6)  
[2] - [Chef 0.10.6 Released - Chef Blog | Chef](http://www.opscode.com/blog/2011/12/14/chef-0-10-6-released/)

On Tue, May 8, 2012 at 7:22 AM, Soula, William [wsoula@mobicorp.com](mailto:wsoula@mobicorp.com) wrote:

> base\_install\_path=node['mobi.GIS']['install']['install\_path']  
> installer\_install\_path=File.join(base\_install\_path,"installer")  
> installer\_config\_properties\_file =  
> File.join(installer\_install\_path,"mobi.GIS-install-config.properties")  
> template installer\_config\_properties\_file do  
> source "mobi.GIS-config-ant-properties.erb"  
> variables(  
> :config =\> node['mobi.integration']['config']  
> )  
> end
> 
> ## [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] INFO: template[c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties] backed up to c:/chef/backup/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties.chef-20120507111115 [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] ERROR: template[c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties] (mobi.GIS::default line /chef/cache/cookbooks/mobi.GIS/recipes/default.rb) has had an error [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] ERROR: template[c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties] (c:/chef/cache/cookbooks/mobi.GIS/recipes/default.rb:12:in `from_file') had an error: tsomerville.pointserve.comtemplate[c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties] (mobi.GIS::default line /chef/cache/cookbooks/mobi.GIS/recipes/default.rb) had an error: Errno::EACCES: Permission denied - c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1314:in `unlink' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1314:in `block in remove_file' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1322:in `platform\_support' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1313:in `remove_file' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:511:in `block in mv' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1423:in `block in fu_each_src_dest' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1439:in `fu\_each\_src\_dest0' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1421:in `fu_each_src_dest' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:504:in `mv' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/provider/template.rb:47:in `block in action_create' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/mixin/template.rb:48:in `block in render\_template' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/1.9.1/tempfile.rb:320:in `open' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/mixin/template.rb:45:in `render\_template' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/provider/template.rb:99:in `render_with_context' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/provider/template.rb:39:in `action\_create' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource.rb:440:in `run_action' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/runner.rb:45:in `run\_action' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/runner.rb:81:in `block (2 levels) in converge' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/runner.rb:81:in `each' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/runner.rb:81:in `block in converge' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource_collection.rb:94:in `block in execute\_each\_resource' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource\_collection/stepable\_iterator.rb:116:in `call' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource_collection/stepable_iterator.rb:116:in `call\_iterator\_block' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource\_collection/stepable\_iterator.rb:85:in `step' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource\_collection/stepable\_iterator.rb:55:in `each_with_index' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource_collection.rb:92:in `execute\_each\_resource' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/runner.rb:76:in `converge' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/client.rb:312:in `converge' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/client.rb:160:in `run' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/application/client.rb:239:in `block in run\_application' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/application/client.rb:229:in `loop' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/application/client.rb:229:in `run\_application' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/application.rb:67:in `run' tsomerville.pointserve.comC:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/bin/chef-client:26:in `\<top (required)\>' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/bin/chef-client:19:in `load' tsomerville.pointserve.com C:/opscode/chef/bin/chef-client:19:in `' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] ERROR: Running exception handlers [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] FATAL: Saving node information to c:/chef/cache/failed-run-data.json [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] ERROR: Exception handlers complete [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] FATAL: Errno::EACCES: template[c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties] (mobi.GIS::default line /chef/cache/cookbooks/mobi.GIS/recipes/default.rb) had an error: Errno::EACCES: Permission denied - c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties
> 
> Could you show the code for the recipe or at least the template resource  
> which is creating the file? Can you also give the stacktrace to the  
> permission denied error?
> 
> The permission denied error makes me think something is wrong with the  
> chef installation or you are using chef incorrectly.
> 
> You should be able to do something like,
> 
> template "/path/to/my.properties" do  
> variables(  
> :config =\> node[:myEnvironmentConfig]  
> )  
> end
> 
> ## On Mon, May 7, 2012 at 3:50 PM, Soula, William [wsoula@mobicorp.com](mailto:wsoula@mobicorp.com) wrote: I guess I can just not use templates and output a file with ruby that contains the values I want and that way I don't have to worry about chef funkiness.
> 
> My environment file has a config section with name, value pairs in it. I  
> am trying to output a template of those name, value pairs by putting the  
> below code into my erb file in chef:  
> \<% @config.each do |setting| -%\>  
> \<%= setting[0] %\>=\<%= setting[1] %\>  
> \<%end-%\>
> 
> This works great the first time as it creates a property file with my name  
> value pairs.
> 
> The problem is when the config section changes. I get a Permission denied  
> error, but if I rerun the recipe then everything works and the new value is  
> in the property file.
> 
> How can I create dynamic property files from the environment json file?
> 
> Thanks,  
> Will
> 
> --  
> -Bryan

--  
-Bryan

---

<div class="post-metadata">

**Author:** ![Paul\_Morton\_BIA](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/paul_morton_bia/32/480_2.png) [@Paul\_Morton\_BIA](https://discourse.chef.io/u/Paul_Morton_BIA)\
**Post date:** [May 8, 2012, 3:22pm UTC](https://discourse.chef.io/t/re-re-re-dynamic-template-file/2813/3 "2012-05-08T15:22:43Z")

</div>

Yeah… This is one of those ruby on windows problems. What I am guessing is happening in your case is that the dynamic template is creating the file in place and setting permissions using the built-in ruby constructs. The net effect is that inherited permissions are removed from the newly created file which can create a scenario where you are unable to change the files (think UAC and privilege escalation). What I have done in the past is fire icacls to reset the permissions of the file after the file is dynamically created.

Now I am not sure what the release plan is, but I do know that @opscode is writing a windows securable plugin which will address many of these types of problems with file permissions.

On May 8, 2012, at 8:12 AM, Bryan Baugher wrote:

> Ugh, windows. Fortunately I have not had the chance to even try chef cookbooks on windows.
> 
> I know that chef 0.10.6 [1] was supposed to have large improvements for windows that could solve your problem. Otherwise I have no idea what the problem could be.
> 
> [1] - [http://wiki.opscode.com/display/chef/Release+Notes#ReleaseNotes-ReleaseNotesChefVersion0.10.6](http://wiki.opscode.com/display/chef/Release+Notes#ReleaseNotes-ReleaseNotesChefVersion0.10.6)  
> [2] - [Chef 0.10.6 Released - Chef Blog | Chef](http://www.opscode.com/blog/2011/12/14/chef-0-10-6-released/)
> 
> On Tue, May 8, 2012 at 7:22 AM, Soula, William [wsoula@mobicorp.com](mailto:wsoula@mobicorp.com) wrote:  
> base\_install\_path=node['mobi.GIS']['install']['install\_path']  
> installer\_install\_path=File.join(base\_install\_path,"installer")  
> installer\_config\_properties\_file = File.join(installer\_install\_path,"mobi.GIS-install-config.properties")  
> template installer\_config\_properties\_file do  
> source "mobi.GIS-config-ant-properties.erb"  
> variables(  
> :config =\> node['mobi.integration']['config']  
> )  
> end
> 
> ## [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] INFO: template[c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties] backed up to c:/chef/backup/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties.chef-20120507111115 [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] ERROR: template[c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties] (mobi.GIS::default line /chef/cache/cookbooks/mobi.GIS/recipes/default.rb) has had an error [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] ERROR: template[c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties] (c:/chef/cache/cookbooks/mobi.GIS/recipes/default.rb:12:in `from_file') had an error: tsomerville.pointserve.com template[c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties] (mobi.GIS::default line /chef/cache/cookbooks/mobi.GIS/recipes/default.rb) had an error: Errno::EACCES: Permission denied - c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1314:in `unlink'[tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1314:in `block in remove_file' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1322:in `platform\_support' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1313:in `remove_file' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:511:in `block in mv' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1423:in `block in fu_each_src_dest' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1439:in `fu\_each\_src\_dest0' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:1421:in `fu_each_src_dest' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/1.9.1/fileutils.rb:504:in `mv' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/provider/template.rb:47:in `block in action_create' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/mixin/template.rb:48:in `block in render\_template' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/1.9.1/tempfile.rb:320:in `open' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/mixin/template.rb:45:in `render\_template' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/provider/template.rb:99:in `render_with_context' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/provider/template.rb:39:in `action\_create' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource.rb:440:in `run_action' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/runner.rb:45:in `run\_action' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/runner.rb:81:in `block (2 levels) in converge' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/runner.rb:81:in `each' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/runner.rb:81:in `block in converge' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource_collection.rb:94:in `block in execute\_each\_resource' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource\_collection/stepable\_iterator.rb:116:in `call' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource_collection/stepable_iterator.rb:116:in `call\_iterator\_block' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource\_collection/stepable\_iterator.rb:85:in `step' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource\_collection/stepable\_iterator.rb:55:in `each_with_index' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource_collection.rb:92:in `execute\_each\_resource' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/runner.rb:76:in `converge' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/client.rb:312:in `converge' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/client.rb:160:in `run' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/application/client.rb:239:in `block in run\_application' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/application/client.rb:229:in `loop' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/application/client.rb:229:in `run\_application' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/application.rb:67:in `run' tsomerville.pointserve.com C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.8/bin/chef-client:26:in `\<top (required)\>' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) C:/opscode/chef/bin/chef-client:19:in `load' tsomerville.pointserve.com C:/opscode/chef/bin/chef-client:19:in `' [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] ERROR: Running exception handlers [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] FATAL: Saving node information to c:/chef/cache/failed-run-data.json [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] ERROR: Exception handlers complete [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out [tsomerville.pointserve.com](http://tsomerville.pointserve.com) [Mon, 07 May 2012 11:11:15 -0500] FATAL: Errno::EACCES: template[c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties] (mobi.GIS::default line /chef/cache/cookbooks/mobi.GIS/recipes/default.rb) had an error: Errno::EACCES: Permission denied - c:/pointserve/mobi.GIS/installer/mobi.GIS-install-config.properties
> 
> Could you show the code for the recipe or at least the template resource which is creating the file? Can you also give the stacktrace to the permission denied error?
> 
> The permission denied error makes me think something is wrong with the chef installation or you are using chef incorrectly.
> 
> You should be able to do something like,
> 
> template "/path/to/my.properties" do  
> variables(  
> :config =\> node[:myEnvironmentConfig]  
> )  
> end
> 
> ## On Mon, May 7, 2012 at 3:50 PM, Soula, William [wsoula@mobicorp.com](mailto:wsoula@mobicorp.com) wrote: I guess I can just not use templates and output a file with ruby that contains the values I want and that way I don't have to worry about chef funkiness.
> 
> My environment file has a config section with name, value pairs in it. I am trying to output a template of those name, value pairs by putting the below code into my erb file in chef:  
> \<% @config.each do |setting| -%\>  
> \<%= setting[0] %\>=\<%= setting[1] %\>  
> \<%end-%\>
> 
> This works great the first time as it creates a property file with my name value pairs.
> 
> The problem is when the config section changes. I get a Permission denied error, but if I rerun the recipe then everything works and the new value is in the property file.
> 
> How can I create dynamic property files from the environment json file?
> 
> Thanks,  
> Will
> 
> --  
> -Bryan
> 
> --  
> -Bryan
