# Re: Template's "cookbook" attribute being ignored

**URL:** <https://discourse.chef.io/t/re-templates-cookbook-attribute-being-ignored/1802>\
**Category:** Chef Infra (archive)\
**Created:** [April 6, 2011, 4:56pm UTC](https://discourse.chef.io/t/re-templates-cookbook-attribute-being-ignored/1802 "2011-04-06T16:56:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan\_Matthews](https://avatars.discourse-cdn.com/v4/letter/j/fbc32d/32.png) [@Jonathan\_Matthews](https://discourse.chef.io/u/Jonathan_Matthews)\
**Post date:** [April 6, 2011, 4:56pm UTC](https://discourse.chef.io/t/re-templates-cookbook-attribute-being-ignored/1802/1 "2011-04-06T16:56:19Z")

</div>

On 5 April 2011 15:56, Jonathan Matthews [contact@jpluscplusm.com](mailto:contact@jpluscplusm.com) wrote:

> On 4 April 2011 21:55, Jonathan Matthews [contact@jpluscplusm.com](mailto: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](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](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

> **[Jonathan Matthews :: Words Typed, Great Rates For Cash](https://www.jpluscplusm.com)**
