On Thu, Dec 23, 2010 at 10:30:22AM -0800, Me wrote:
> I'm on 2.6.4, and I have one template that just won't work. I want to
> only print a section when a variable has a particular value. Depending
> on hostname, a variable called "dns_role" has the value of either
> "master" or "slave".
> 
> This template snippet works for a named.conf file template (not part
> of the problem):
> 
> <% if has_variable?("dns_role") && dns_role != '' then %>
> include "/etc/zones_<%= dns_role %>.conf";
> <% end %>
> 
> The named.conf file has either "master" or "slave" inserted, and the
> proper BIND config file is there from another process.
> 
> Now - the problem - is that this snippet doesn't ever print anything
> (for a shell script that actually generates the zone files and
> named.conf files):
> 
>   <% if dns_role == "master" then %>
>                 #
>                 # I'm a BIND <%= dns_role %>
>                 #
>                 cp -f $startdir/zones/* /var/named/internal/
>   <% end %>
> 

My first idea was the usage of "then" because I'd only ever see ruby
statements like

if a==b
  do_something
end

But I just tried it and it did worked. Then just another comment: If you
use <%if ... -%> and <% end -%> than these statements will not produce
blank lines in your final file...

To your actual problem: What happens if you just put a <%= dns_role %>
in front of your if-statement. Are you sure dns_role is actual set to the
correct value (no hidden blanks or anything)? If dns_role is correctly
set but your if-statement is still not evaluated try with dns_role.to_s
to make sure its a string. Or maybe there is syntax error, missing
bracket or whatever in your template (or node manifest that mixes up
scope)

-Stefan

Attachment: pgpdu2TK5yFJH.pgp
Description: PGP signature

Reply via email to