On 2018-07-15 15:45, Helmut Schneider wrote:
Henrik Lindberg wrote:

On 2018-07-14 13:47, Johan Fleury wrote:
I meant bool2str, sorry.


https://github.com/puppetlabs/puppetlabs-stdlib/blob/master/README.md#bool2str


Helmut, before digging yourself deeper into problems by using work
around on top of problems - do consider using EPP since it protects
you from the issues of needing to know how puppet represents things
in Ruby; which is complicated as puppet handles things differently in
different parts of the code base for backwards compatibility reasons.

Many of the functions in stdlib are smelly as they are sometimes quite
imprecise and not always correct. The "bool2str" however, does what
it is supposed to, but will error if not given a boolean true or
false.  That is, it will error if given empty string, undef, or the
ruby symbol :undef. (Thus, in your case, you may get another
surprise/error if you try to use that function).

In puppet language (in EPP) you can do this:

$result = if $val { 'it is truthy' } else { 'it is falsey' }

I find the existing documentation in the net very confusing so I
havent' used epp yet. E.g. according to
https://puppet.com/docs/puppet/5.4/lang_template_epp.html this should
work:

content => epp("openvpn/etc/openvpn/config.epp", { openvpnConf =>
$openvpnConf, openvpnMode => $openvpnMode, instance => $instance }),

<%- | 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.

       String $openvpnMode,
       String $category,
       String $parameters,
       String $instance
| -%>

<% ({
'Misc' => [
         'script-security',
         'plugin',
         'up',
         'down',
],
}).each |$category, $parameters| { -%>
<%= $category %>
<% } -%>

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:6:
6 at /etc/puppetlabs/code/modules/openvpn/manifests/init.pp:28:22 on
node h2786452.stratoserver.net

The same documentation uses different sysntax, once without '$'

$servers.each |server|

That is wrong, cannot work, should be $server

and then with '$'

$ntp::restrict.flatten.each |$restrict|


That is correct.

What is correct? And what is wrong with the code above? Do I need to
declare only variables that I pass to the epp or also those I create
within the epp?


You do not need to declare those that you create inside of the EPP.
They are like local variables inside the EPP.

Hope that helps.
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/pig0g2%24vj8%241%40blaine.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to