Template's "cookbook" attribute being ignored


#1

I’m running 0.9.12 on Ubuntu Lucid (server) and Debian Squeeze (client).

The client appears to be ignoring the “cookbook” attribute set inside
a template definition.

Here’s the code from the recipe inside my “filesystem” cookbook (much
code redacted and irrelevant, given logs, below). The behaviour is
the same, regardless of which “cookbook” line is commented out:

tmpl_cookbook = config[“cookbook”] || “templates”

code redacted here

log(“FS:TMPL: cookbook == #{tmpl_cookbook}”) { level :debug }

NO code redacted here

template name do
action tmpl_action
cookbook “templates”
#cookbook tmpl_cookbook
path tmpl_path
source config[“source”]
group config[“group”]
mode config[“mode”]
owner config[“owner”]
local config[“local”] if config[“local”]
variables( auto_vars.merge(vars) )
end

The debug logs show the following, regardless of which line (above) is
commented and which is active. Both show the client “looking for
template etc-default-tftpd-hpa.erb in cookbook “filesystem””, which is
where the code is defined:

[Mon, 04 Apr 2011 21:42:29 +0100] DEBUG: FS:TMPL: path ==
/etc/default/tftpd-hpa
[Mon, 04 Apr 2011 21:42:29 +0100] DEBUG: Processing log[FS:TMPL:
cookbook == templates] on boot00
[Mon, 04 Apr 2011 21:42:29 +0100] DEBUG: FS:TMPL: cookbook == templates
[Mon, 04 Apr 2011 21:42:29 +0100] DEBUG: Processing
template[tftpd-hpa_defaults] on boot00.nix.sys.7digital.net
[Mon, 04 Apr 2011 21:42:29 +0100] DEBUG: looking for template
etc-default-tftpd-hpa.erb in cookbook “filesystem”
[Mon, 04 Apr 2011 21:42:29 +0100] DEBUG: Not storing
cookbooks/templates/templates/default/etc-default-tftpd-hpa.er

What am I missing? I’ve tried directly setting the cookbook, and via a
variable, so I don’t think I’m hitting the same issue that Charles
Duffy described in “param[:name] bizarreness when nesting defines”
(Jan 19th). Again, it’s 0.9.12 on ubuntu+debian.

Jonathan

Jonathan Matthews
London, UK
http://www.jpluscplusm.com/contact.html


#2

On 4 April 2011 21:55, Jonathan Matthews contact@jpluscplusm.com wrote:

I’m running 0.9.12 on Ubuntu Lucid (server) and Debian Squeeze (client).

Correction: 0.9.14 on the Debian client.

The debug logs show the following, regardless of which line (above) is
commented and which is active. Both show the client “looking for
template etc-default-tftpd-hpa.erb in cookbook “filesystem””, which is
where the code is defined:

[Mon, 04 Apr 2011 21:42:29 +0100] DEBUG: FS:TMPL: path ==
/etc/default/tftpd-hpa
[Mon, 04 Apr 2011 21:42:29 +0100] DEBUG: Processing log[FS:TMPL:
cookbook == templates] on boot00
[Mon, 04 Apr 2011 21:42:29 +0100] DEBUG: FS:TMPL: cookbook == templates
[Mon, 04 Apr 2011 21:42:29 +0100] DEBUG: Processing
template[tftpd-hpa_defaults] on boot00.nix.sys.7digital.net
[Mon, 04 Apr 2011 21:42:29 +0100] DEBUG: looking for template
etc-default-tftpd-hpa.erb in cookbook “filesystem”

I think this last line is a lie. It comes from
https://github.com/opscode/chef/blob/master/chef/lib/chef/provider/template.rb#L63
and is directly contradicted by the contents of “cookbook” at
https://github.com/opscode/chef/blob/master/chef/lib/chef/provider/template.rb#L68.
Popping a debug log in between L68/69, I can see that "cookbook"
contains the correct setting from the recipe/resource interaction.

I’m still not sure why I’m seeing an error here. Here’s the error
(which I hadn’t included before, so as not to muddy the waters). I
wonder if some other code, elsewhere, is also making the mistake of
not properly finding out which cookbook the template is in? (the log
line “decided template etc-default-tftpd-hpa.erb is in cookbook
templates” is my local debug addition to template.rb#L68.5, as
described above).

[Tue, 05 Apr 2011 15:06:59 +0100] DEBUG: FS:TMPL: path      ==
/etc/default/tftpd-hpa
[Tue, 05 Apr 2011 15:06:59 +0100] DEBUG: Processing log[FS:TMPL:
cookbook  == templates] on boot00
[Tue, 05 Apr 2011 15:06:59 +0100] DEBUG: FS:TMPL: cookbook  == templates
[Tue, 05 Apr 2011 15:06:59 +0100] DEBUG: Processing
template[tftpd-hpa_defaults] on boot00
[Tue, 05 Apr 2011 15:06:59 +0100] DEBUG: looking for template
etc-default-tftpd-hpa.erb in cookbook "filesystem"
[Tue, 05 Apr 2011 15:06:59 +0100] DEBUG: decided template
etc-default-tftpd-hpa.erb is in cookbook templates
[Tue, 05 Apr 2011 15:06:59 +0100] DEBUG: Not storing
cookbooks/templates/templates/default/etc-default-tftpd-hpa.erb, as
the cache is up to date.
[Tue, 05 Apr 2011 15:06:59 +0100] ERROR: Running exception handlers
[Tue, 05 Apr 2011 15:06:59 +0100] ERROR: Exception handlers complete
[Tue, 05 Apr 2011 15:06:59 +0100] DEBUG: Re-raising exception:
NoMethodError - undefined method `-' for nil:NilClass
/usr/lib/ruby/1.8/chef/mixin/template.rb:74:in `source_listing'
  /usr/lib/ruby/1.8/chef/mixin/template.rb:90:in `to_s'
  /usr/lib/ruby/1.8/chef/runner.rb:91:in `converge'
  /usr/lib/ruby/1.8/chef/resource_collection.rb:94
  /usr/lib/ruby/1.8/chef/resource_collection/stepable_iterator.rb:116:in `call'
  /usr/lib/ruby/1.8/chef/resource_collection/stepable_iterator.rb:116:in
`call_iterator_block'
  /usr/lib/ruby/1.8/chef/resource_collection/stepable_iterator.rb:85:in `step'
  /usr/lib/ruby/1.8/chef/resource_collection/stepable_iterator.rb:104:in
`iterate'
  /usr/lib/ruby/1.8/chef/resource_collection/stepable_iterator.rb:55:in
`each_with_index'
  /usr/lib/ruby/1.8/chef/resource_collection.rb:92:in `execute_each_resource'
  /usr/lib/ruby/1.8/chef/runner.rb:84:in `converge'
  /usr/lib/ruby/1.8/chef/client.rb:268:in `converge'
  /usr/lib/ruby/1.8/chef/client.rb:171:in `run'
  /usr/lib/ruby/1.8/chef/application/client.rb:222:in `run_application'
  /usr/lib/ruby/1.8/chef/application/client.rb:212:in `loop'
  /usr/lib/ruby/1.8/chef/application/client.rb:212:in `run_application'
  /usr/lib/ruby/1.8/chef/application.rb:62:in `run'
  /usr/bin/chef-client:26

FWIW, this error occurs both when the erb file is empty and when it’s
a static text file. I believe I’ve seen this error in the past when
the client can’t get the template, but here’s the error occurring
during a run started just after I’ve changed the template contents
(hence the client has to pull down the new contents, but only if it
identifies the cookbook containing the template correctly; which it
does):

[Tue, 05 Apr 2011 15:12:44 +0100] DEBUG: Processing
template[tftpd-hpa_defaults] on boot00
[Tue, 05 Apr 2011 15:12:44 +0100] DEBUG: looking for template
etc-default-tftpd-hpa.erb in cookbook "filesystem"
[Tue, 05 Apr 2011 15:12:44 +0100] DEBUG: decided template
etc-default-tftpd-hpa.erb is in cookbook templates
[Tue, 05 Apr 2011 15:12:44 +0100] DEBUG: Signing the request as boot00
[Tue, 05 Apr 2011 15:12:44 +0100] DEBUG: String to sign: 'Method:GET
Hashed Path:XXXXXXXXXX
X-Ops-Content-Hash:XXXXXXX
X-Ops-Timestamp:2011-04-05T14:12:44Z
X-Ops-UserId:boot00
Header hash: {"X-Ops-Content-Hash"=>"", "X-Ops-Authorization-1"=>"",
"X-Ops-Userid"=>"boot00", "X-Ops-Sign"=>"version=1.0",
"X-Ops-Authorization-2"=>"", "X-Ops-Authorization-3"=>"",
"X-Ops-Authorization-4"=>"", "X-Ops-Authorization-5"=>"",
"X-Ops-Authorization-6"=>"",
"X-Ops-Timestamp"=>"2011-04-05T14:12:44Z"}
[Tue, 05 Apr 2011 15:12:44 +0100] DEBUG: Sending HTTP Request via GET
to chef:443/cookbooks/templates/0.0.1/files/be74256428038a92c7e3dafd2bb2bee3
[Tue, 05 Apr 2011 15:12:45 +0100] DEBUG: Streaming download from
https://chef/cookbooks/templates/0.0.1/files/be74256428038a92c7e3dafd2bb2bee3
to tempfile /tmp/chef-rest20110405-7042-1wyfuqb-0
[Tue, 05 Apr 2011 15:12:45 +0100] INFO: Storing updated
cookbooks/templates/templates/default/etc-default-tftpd-hpa.erb in the
cache.
[Tue, 05 Apr 2011 15:12:45 +0100] ERROR: Running exception handlers
[Tue, 05 Apr 2011 15:12:45 +0100] ERROR: Exception handlers complete
[Tue, 05 Apr 2011 15:12:45 +0100] DEBUG: Re-raising exception:
NoMethodError - undefined method `-' for nil:NilClass
/usr/lib/ruby/1.8/chef/mixin/template.rb:74:in `source_listing'
  /usr/lib/ruby/1.8/chef/mixin/template.rb:90:in `to_s'
  /usr/lib/ruby/1.8/chef/runner.rb:91:in `converge'
  /usr/lib/ruby/1.8/chef/resource_collection.rb:94
  /usr/lib/ruby/1.8/chef/resource_collection/stepable_iterator.rb:116:in `call'
  /usr/lib/ruby/1.8/chef/resource_collection/stepable_iterator.rb:116:in
`call_iterator_block'
  /usr/lib/ruby/1.8/chef/resource_collection/stepable_iterator.rb:85:in `step'
  /usr/lib/ruby/1.8/chef/resource_collection/stepable_iterator.rb:104:in
`iterate'
  /usr/lib/ruby/1.8/chef/resource_collection/stepable_iterator.rb:55:in
`each_with_index'
  /usr/lib/ruby/1.8/chef/resource_collection.rb:92:in `execute_each_resource'
  /usr/lib/ruby/1.8/chef/runner.rb:84:in `converge'
  /usr/lib/ruby/1.8/chef/client.rb:268:in `converge'
  /usr/lib/ruby/1.8/chef/client.rb:171:in `run'
  /usr/lib/ruby/1.8/chef/application/client.rb:222:in `run_application'
  /usr/lib/ruby/1.8/chef/application/client.rb:212:in `loop'
  /usr/lib/ruby/1.8/chef/application/client.rb:212:in `run_application'
  /usr/lib/ruby/1.8/chef/application.rb:62:in `run'
  /usr/bin/chef-client:26


Jonathan Matthews
London, UK
http://www.jpluscplusm.com/contact.html