Q: does puppet epp template syntax support elsif conditionals?
I am receiving the following error when building a template with puppet epp:
Evaluation Error: Error while evaluating a Function Call, epp(): Invalid EPP: Syntax error at 'elsif'
It seems like puppet syntax should support the use of elsif here. I've looked around and can't seem to see much on this topic.
My template:
<% if $facts[env] == test { %> foo:
<% if $facts[site] == uk { %> bar uk: <% } %>
<% elsif $facts[site] == fr { %> bar fr: <% } %>
<% else $facts[site] == us { %> bar us: <% } %>
<% } %>
Latest Edits:
Along with John Bollinger's helpful comments below, there shouldn't be any conditions outside of the else. If there are, Puppet throws the misleading error message above. So for my use-case the below works well:
<%
if $facts[env] == test {
%> foo:
<%
if $facts[site] == uk {
%> bar uk: <%
} elsif $facts[site] == fr {
%> bar fr: <%
} else {
%> bar us: <%
}
}
%>
The problem is that there is template text (albeit all whitespace) between the closing brace of the
ifblock and theelseif. From the perspective of the Puppet code, template text is effectively an output statement, and that cannot appear between an}and anelsif.Since it seems unlikely that you actually want the particular whitespace that is causing the issue, I think you could resolve it by suppressing it:
That leaves the linebreak and whitespace after
foo:, but suppresses the whitespace between theifandelseif, between theelseifandelse, and following theelse.Alternatively, I usually find template code easier to read when it has fewer tags. Like this, maybe: