Re: Template's "cookbook" attribute being ignored


#1

On 5 April 2011 15:56, Jonathan Matthews contact@jpluscplusm.com wrote:

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.

[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 still think this is the case. It wasn’t anything to do with my
problem, however.

The problem is that not all legal ruby hashes may be passed to a
template’s variables() attribute/method. Specifically, this example
breaks with very unhelpful, unspecific error messages:

template “foobar” do
path “/tmp/foobar"
source “whatever"
variables ( :”-foo” => “bar” )
end

I suppose the problem here is that the method of instantiating each
key as an instance variable breaks when the key isn’t a legal variable
name.

Whilst this may not be a problem when choosing the variable names
individually, it is a problem when trying to pass a subtree of node
through to the template and the particular branch one starts at (a)
may contain -, +, or other characters invalid in variable names and
(b) is editable by users via the WebUI. (FWIW I’m trying to avoid
just referencing node directly so as to decouple the “view” from the
"model" - one of the fundamental concepts behind the “think of it like
an MVC” idea, IIRC).

Any ideas? I’m going to gsub anything not matching [a-zA-Z0-9] to
underscores for now and update their templates, but that’s hardly
ideal - especially in a multi-admin environment.

Jonathan

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