On 2018-07-16 10:21, Helmut Schneider wrote:
Henrik Lindberg wrote:

On 2018-07-15 15:45, Helmut Schneider wrote:
<%- | Hash $openvpnConf,

It is important that there is no text before the opening <%-
Not sure if you have a blank line there. If so you will get a syntax
error because of the text output before the declaration of the
parameters.

Thank you.

I managed to get it work with the following code:

<%- | Hash $openvpnConf, String $openvpnMode, String $instance | -%>
<% ({
'Mode' => [
         "$openvpnMode",
],
}).each |$category, $parameters| { -%>
### <%= $category %> ###
<% $parameters.each |$parameter| { -%>
<% if $parameter == 'remote' { -%>
<%= $parameter %> <%= $openvpnConf['server'] %> <%=
$openvpnConf['port'] %>
<% } else { -%>
<%= $parameter %> <%= $openvpnConf[$parameter] %>
<% } -%>
<% } %>
<% } -%>

What does not work yet is to add something after <%- | [...] | -%>,
everything I add (here <%= $openvpnMode %>) gives an error. E.g.:

<%- | Hash $openvpnConf, String $openvpnMode, String $instance | -%>
<%= $openvpnMode %>
<% ({
'Mode' => [
         "$openvpnMode",
],
}).each |$category, $parameters| { -%>
### <%= $category %> ###
<% $parameters.each |$parameter| { -%>
<% if $parameter == 'remote' { -%>
<%= $parameter %> <%= $openvpnConf['server'] %> <%=
$openvpnConf['port'] %>
<% } else { -%>
<%= $parameter %> <%= $openvpnConf[$parameter] %>
<% } -%>
<% } %>
<% } -%>

fails with

Error: Could not retrieve catalog from remote server: Error 500 on
SERVER: Server Error: Evaluation Error: Error while evaluating a
Function Call, epp(): Invalid EPP: Ambiguous EPP parameter expression.
Probably missing '<%-' before parameters to remove leading whitespace
at
/etc/puppetlabs/code/modules/openvpn/templates/etc/openvpn/config.epp:2:
20 at /etc/puppetlabs/code/modules/openvpn/manifests/init.pp:29:22 on
node h2786452

How can I fix this?


It is a bug, please file a ticket in puppet's Jira for project PUP.

Looks like it is confused by the use of ( ) around your hash.

I tried this as a workaround:

$template = @(END)
<%-| $x | -%>
<%= $x -%>
<%- $y = {
  'Mode' => [ $x, ],
}
$y.each |$category, $parameters| { -%>
<%= $category %> = <%= $parameters %>
<%- } -%>
END
notice inline_epp($template, x => 'testing')

See you I use an assignment to a local variable $y to get a hash to work with.

What epp does is to translate <%= ... %> to a print-string expression.
When that is followed by a left parenthesis it seems to think it is a call i.e. as if you had written the following in puppet:

print($x)({...})

Hope that helps you work around the problem.
Best,
- henrik


--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

--
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/pihqat%24t2m%241%40blaine.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to