Trevor Vaughan
2009-Jan-19 19:35 UTC
[Puppet Users] Checking for a class definition within an ERB file.
Hi all, I''ve been toying around with this for a little while and find that my ruby-fu is weak. In the Puppet language, I can do the following: if defined(Class["foo"]) { ...do stuff... } How do I do that in an ERB file? I.e. <% if class(foo) then %>do stuff<% end %> Or, is this impossible? Thanks, Trevor --~--~---------~--~----~------------~-------~--~----~ 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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Andrew Shafer
2009-Jan-19 21:21 UTC
[Puppet Users] Re: Checking for a class definition within an ERB file.
Trevor, What version of Puppet? You could pull that logic up into Puppet and use ''defined'' to set a variable then use that in the template. Or if you have to do it in the template, you should be able to call that same function with ''function_defined'' depending on the version of Puppet. You can try and see what methods you have in your version. <% methods.sort.each do |m| -%> <%= m %> is part of the current scope <% end -%> Cheers, Andrew On Mon, Jan 19, 2009 at 12:35 PM, Trevor Vaughan <peiriannydd@gmail.com>wrote:> > Hi all, > > I''ve been toying around with this for a little while and find that my > ruby-fu is weak. > > In the Puppet language, I can do the following: > > if defined(Class["foo"]) { ...do stuff... } > > How do I do that in an ERB file? > > I.e. > > <% if class(foo) then %>do stuff<% end %> > > Or, is this impossible? > > Thanks, > > Trevor > > > >--~--~---------~--~----~------------~-------~--~----~ 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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Trevor Vaughan
2009-Jan-19 21:42 UTC
[Puppet Users] Re: Checking for a class definition within an ERB file.
Should have posted that...0.24.6. I tried pulling it up into Puppet, but it wasn''t very clean since I had to do both an ''import foo'' and an ''include foo'' to get it to see the variables in a module. I''ll try ''function_defined'' and see what happens. Thanks, Trevor On Mon, Jan 19, 2009 at 16:21, Andrew Shafer <andrew@reductivelabs.com> wrote:> Trevor, > > What version of Puppet? > > You could pull that logic up into Puppet and use ''defined'' to set a variable > then use that in the template. > > Or if you have to do it in the template, you should be able to call that > same function with ''function_defined'' depending on the version of Puppet. > > You can try and see what methods you have in your version. > > <% methods.sort.each do |m| -%> > <%= m %> is part of the current scope > <% end -%> > > Cheers, > Andrew > > > > On Mon, Jan 19, 2009 at 12:35 PM, Trevor Vaughan <peiriannydd@gmail.com> > wrote: >> >> Hi all, >> >> I''ve been toying around with this for a little while and find that my >> ruby-fu is weak. >> >> In the Puppet language, I can do the following: >> >> if defined(Class["foo"]) { ...do stuff... } >> >> How do I do that in an ERB file? >> >> I.e. >> >> <% if class(foo) then %>do stuff<% end %> >> >> Or, is this impossible? >> >> Thanks, >> >> Trevor >> >> > > > > >--~--~---------~--~----~------------~-------~--~----~ 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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---