On Thursday, February 14, 2013 10:35:50 AM UTC-6, Marc Bolós wrote: > > Dear, > > I've been using puppet for some time now. Usually when I have a problem I > read all documentation refered to the problem I have. > > Recently I was trying to write a puppet erb template, that checks if host > has one class defined, and if it has then writes some text to cron. > > After a lot of googleing, I found that the best way to do this was: >
Maybe, but better by far is to avoid doing that at all. Specifically, avoid writing DSL code or templates that attempt to inquire whether particular resources have been declared. Such code is inherently parse-order sensitive, and it is, moreover, unnecessary. Although it may at some times seem convenient, it is never *necessary* to inquire whether a given class or resource is (supposed to have been) declared. You can always know, whether in an absolute or a conditional sense. > > <% if classes.include?( 'class1' ) -%> > Some text > <% end -%> > > And this worked. > > But when I try on the same erb file to look for other classes, then it > only processes 1: > <% if classes.include?( 'class1' ) -%> > Some text > <% end -%> > <% if classes.include?( 'class2' ) -%> > Blah Blah Blah > <% end -%> > > I can find only "Some text" inside file. But this host has class2 also > declared. If I remove if classes.include of class1, and leave alone class2 > text, then I can see the text of class2. > > Did anyone had this issue before? > > In all likelihood, this is a parse-order problem. If the template() or inline_template() call by which you are evaluating the template is parsed before class2 has been assigned to the target node, then the template will not see it in the 'classes' array. Such problems can sometimes be managed, but even then there is usually a better approach. Inasmuch as your example is pretty synthetic, I can't say what a better approach would be. If you describe your real problem more then we might have better suggestions. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.