[chef] Re: Why will chef not read a file in a template?


Chronological Thread 
  • From: Morgan Blackthorne < >
  • To: " " < >
  • Subject: [chef] Re: Why will chef not read a file in a template?
  • Date: Sat, 22 Feb 2014 06:22:37 -0800

Typically the logic should be in the recipe, not the template. I'm not sure the templating system has access to resolve Chef::Config from what the error is showing.

Alternatively, you should be able to at least form the full filename and pass it to the template as a variable. Doing the logic like this inside the template seems doubly wrong.

Ah, sorry, make that triply wrong... if you want variables inside a string it needs to be double quoted, not single quoted.

--
~*~ StormeRider ~*~

"Every world needs its heroes [...] They inspire us to be better than we are. And they protect from the darkness that's just around the corner."

(from Smallville Season 6x1: "Zod")

On why I hate the phrase "that's so lame"... http://bit.ly/Ps3uSS


On Sat, Feb 22, 2014 at 3:19 AM, David Montgomery < " target="_blank"> > wrote:
What is the deal with chef and trying to read a file?  I mean..the file is there.  The below is in a template. 


 discovery.zen.ping.unicast.hosts: <%=File.read('#{Chef::Config[:file_cache_path]}/unicast_hosts')%>

ls -al /var/chef/cache/
-rw-r--r--  1 root root        19 Feb 22 06:05 unicast_hosts

And yes #{Chef::Config[:file_cache_path]} = /var/chef/cache/



[2014-02-22T06:15:12-05:00] INFO: Sending resource update report (run-id: e5f200ea-5d0b-4652-b02a-3b836357ca5b)
[2014-02-22T06:15:12-05:00] ERROR:

Chef::Mixin::Template::TemplateError (No such file or directory - #{Chef::Config[:file_cache_path]}/unicast_hosts) on line #327:

325:
326:
327: discovery.zen.ping.unicast.hosts: <%=File.read('#{Chef::Config[:file_cache_path]}/unicast_hosts')%>
328:
329:










Archive powered by MHonArc 2.6.16.

§