[chef] Re: seeking variable template help


Chronological Thread 
  • From: AJ Christensen < >
  • To: " " < >
  • Subject: [chef] Re: seeking variable template help
  • Date: Thu, 11 Jun 2015 23:03:50 +0000

You're missing the `node[:bind][role]` etc. the node object allows you to access attributes there.

In general I'd recommend using the variables() parameter to the template resource to bind particular attributes to known variables in advance, then refer to those instance variables in the template, kind of as a known interface between the node, the recipe and the template itself. Means you can change the templates variables from one attribute to another, more readily.

cheers,

--aj

On Fri, Jun 12, 2015 at 11:01 AM Jennifer Fountain < "> > wrote:
Here is what I am trying to do:

<% %w[zone1 zone1].each do |role| -%>
zone "<%= role %>.domain.com" in {
    type master;
    file "<%= role %>.domain.conf";
    <% if [:bind][role][:notify] != nil %>
        notify yes;
        also-notify { [<%= [:bind][role][:notify_ip] %>; };
    <% end %>
    allow-update { <%= [:bind][role][:allow_update_ip] %>; };

};
<% end %>

This works as expected:
<% %w[zone1 zone1].each do |role| -%>
zone "<%= role %>.domain.com" in {
    type master;
    file "<%= role %>.domain.conf";
};
<% end %>

This not so much:
    <% if [:bind][role][:notify] != nil %>
        notify yes;
        also-notify { [<%= [:bind][role][:notify_ip] %>; };
    <% end %>
    allow-update { <%= [:bind][role][:allow_update_ip] %>; };

}; 

I have tried several different variations but chef_zero is still throwing errors. 

eg: Chef::Mixin::Template::TemplateError (no implicit conversion of String into Integer) on line #68:

Is this not possible? Thanks for any advice!

--


Jennifer Fountain
DevOPS



Archive powered by MHonArc 2.6.16.

§