Seeking variable template help

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

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 jfountain@meetme.com
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

Ah Thanks! I cannot believe I missed that. I guess that's what happens when
you look at a screen for a long time :smiley: Thanks! works great now.

On Thu, Jun 11, 2015 at 7:03 PM, AJ Christensen <aj@junglistheavy.industries

wrote:

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 jfountain@meetme.com
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

--

Jennifer Fountain
DevOPS