[colug-432] ERB variable expansion

Rick Hornsby richardjhornsby at gmail.com
Mon Oct 19 17:48:01 EDT 2015


Using Puppet 3.6 (it's what comes with RHEL7...)  I'm trying to take an array and turn it into a semi-complex string (a series of or'd LDAP DNs), which ends up in a .erb template.  I've fought with writing the loop to create the long string in the puppet params.pp manifest, and it's a pain.  It looks like .each, .map etc aren't available until Puppet 4.0.

I decided to write the loop in the template.  That wasn't working, so that's when I tried to do it in the manifest, and now I'm back to the template.  If I only needed this string once, I would write it inline once using <%= ... %>.  I need this long string twice in the file, so it makes sense to somehow generate it once, and then use it later.  Does erb even support such a thing?

I have this:

<%
@memberList = ""
@groups.each do |group|
	@memberList += "(memberOf=cn=${group},cn=Users,dc=foo,dc=com)"
end
-%>

No matter what I do here, I can't seem to get ${group} (or @group, etc) to expand in that string - it is always written out as the string literal.  You can see, however, that constructing this string more than once increases the risk of a mistake in one or both places - why I want to generate it once.

I do _not_ want to print it or output anything at this point in the template.  Printing <%= %> it here would be useless because it is part of 2 longer lines later in the configuration file.

Is there another approach to handling this that I'm missing?

thanks!





More information about the colug-432 mailing list