Puppet- ERB template- Question about defined classes

puppetrubyruby-on-rails

Puppet template files are erb rails files.

I want the line:

Include modsecurity.d/*.conf

To be included in the final file if the class mod_security is included.

From the puppet docs:
http://docs.puppetlabs.com/guides/templating.html

And this snippet will print all the
defined class in the catalog:

<% classes.each do |klass| -%>
The class <%= klass %> is defined
<% end -%>

Conditional:

<% if broadcast != "NONE" %>        broadcast <%= broadcast %> <% end %>

I am new to the syntax. Does defined mean the same as included? For the conditional how would I check a particular class i.e. if isdefined(mod_security)…?

Best Answer

Defined classes does mean that the class is included. Just to be clear, the <% if broadcast ... bit is not the way to check the inclusion of the broadcast class, but rather to syntax of a conditional using the value of the broadcast variable, the classes array contains the names of all the defined classes.

This would be how you would check for the mod_security class for instance:

<% if classes.include?("mod_security") %>
conditional text
<% end %>

Edit:

Whoops...the method is called include? not includes?. Fixed above.