Yup, that works.  FYI there's a bug in the docs.  The example shown here:
http://docs.puppetlabs.com/guides/templating.html#undefined-variables

Looks like so:
<% if has_variable?("myvar") then %>
myvar has <%= myvar %> value
<% end %>

On Mon, May 23, 2011 at 4:59 PM, Nan Liu <n...@puppetlabs.com> wrote:

> On Mon, May 23, 2011 at 4:09 PM, Aaron Grewell <aaron.grew...@gmail.com>
> wrote:
> > I've got a conditional statement that isn't working the way I expect.
> I've
> > created a define() for building network interfaces, but two of the
> entries
> > (master & slave) are only appropriate for bonded interfaces.  I would
> like
> > them to be completely excluded from regular interfaces.  This seems easy
> > enough according to the docs, set master & slave to 'undef' and use the
> 'if
> > has_variable' syntax in the template.  It doesn't work though.  I also
> tried
> > using 'if variable != "undef"' but this also does not work.
> Interestingly
> > the results of the two are exactly the same.  I'm clearly missing
> > something.  How do I get the template to skip these lines?
> >
> > The results end up looking like this:
> > ### This file is being managed by Puppet
> > ### DO NOT EDIT
> > DEVICE=eth0
> > BOOTPROTO=none
> > ONBOOT=yes
> > IPADDR=192.168.1.1
> > NETMASK=255.255.255.0
> > HWADDR=eth0
> > MASTER=undef
> > SLAVE=undef
> >
> > The define is built like so:
> >     define network_interface (
> >         $bootproto,
> >         $onboot,
> >         $ipaddr  = undef,
> >         $netmask = undef,
> >         $hwaddr  = undef,
> >         $master  = undef,
> >         $slave   = undef
> >     ){  <SNIP> }
> >
> > And the template looks like:
> > ### This file is being managed by Puppet
> > ### DO NOT EDIT
> > DEVICE=<%= name %>
> > BOOTPROTO=<%= bootproto %>
> > ONBOOT=<%= onboot %>
> > <% if ipaddr != "undef" -%>
> > IPADDR=<%= ipaddr %>
> > <% end -%>
> > <% if netmask != "undef" -%>
> > NETMASK=<%= netmask %>
> > <% end -%>
> > <% if final_hwaddr != "undef" -%>
> > HWADDR=<%= final_hwaddr %>
> > <% end -%>
> > <% if master != "undef" -%>
> > MASTER=<%= master %>
> > <% end -%>
> > <% if slave != "undef" -%>
> > SLAVE=<%= slave %>
> > <% end -%>
> >
> > Or I also tried:
> > ### This file is being managed by Puppet
> > ### DO NOT EDIT
> > DEVICE=<%= name %>
> > BOOTPROTO=<%= bootproto %>
> > ONBOOT=<%= onboot %>
> > <% if has_variable?("ipaddr") then -%>
> > IPADDR=<%= ipaddr %>
> > <% end -%>
> > <% if has_variable?("netmask") then -%>
> > NETMASK=<%= netmask %>
> > <% end -%>
> > <% if has_variable?("final_hwaddr") then -%>
> > HWADDR=<%= final_hwaddr %>
> > <% end -%>
> > <% if has_variable?("master") then -%>
> > MASTER=<%= master %>
> > <% end -%>
> > <% if has_variable?("slave") then -%>
> > SLAVE=<%= slave %>
> > <% end -%>
>
> Don't quote it, has_variable?(slave).
>
> Nan
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To post to this group, send email to puppet-users@googlegroups.com.
> To unsubscribe from this group, send email to
> puppet-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/puppet-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to