On 2018-07-19 17:15, Helmut Schneider wrote:
Hi,

---
profiles:
   vpn:
     openvpn:
       defaults:
         client:
           dev:               'tun'
           proto:             'udp'
           resolv-retry:      'infinite'
           nobind:
           user:              'nobody'
           group:             'nogroup'
           persist-key:
           persist-tun:
           ca:                '/etc/openvpn/ca-charlieroot.de.crt'
           cert:              '/etc/openvpn/mail.helmut-ritter.de.crt'
           key:               '/etc/openvpn/mail.helmut-ritter.de.key'
           ns-cert-type:      'server'
           # OpenVPN <= 2.3
           comp-lzo:          'yes'
           # OpenVPN > 2.3
           # compress:          'lz4'
           log-append:        '/var/log/openvpn.log'
           verb:              '4'
           script-security:   '2'
           up:                '/etc/openvpn/update-resolv-conf'

The eep is called by

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

The epp:

<%- | Hash $openvpnConf, String $openvpnMode, String $instance | -%>
<% ({
'Mode' => [
         "$openvpnMode",
],
'Connection' => [
         'remote',
         'proto',
         'dev',
         'persist-tun',
         'nobind',
         'resolv-retry',
         'compress',
         'comp-lzo',
],
'Privileges' => [
         'user',
         'group',
         'persist-key',
],
'Authentication' => [
         'cert',
         'key',
         'ca',
         'ns-cert-type',
],
'Logging' => [
         'verb',
         'log-append',
],
'Misc' => [
         'script-security',
         'plugin',
         'up',
         'down',
],
}).each |$category, $parameters| { -%>
### <%= $category %> ###
<%#= $openvpnConf %>
<% $parameters.each |$parameter| { -%>
<% if $parameter == 'remote' { -%>
<%= $parameter %> <%= $openvpnConf['server'] %> <%=
$openvpnConf['port'] %>
<% } elsif $openvpnConf[$parameter] { -%>
<%= $parameter %> <%= regsubst($openvpnConf[$parameter],
'__INSTANCE__', $instance) %>
<% } elsif defined($openvpnConf[$parameter]) { -%>
<%= $parameter %>
<% } -%>
<% } %>
<% } -%>

The problem: compress does not exist in the hiera but is printed in the
epp. How can I test if the key "compress" exists in the
$openvpnConf-Hash?


You can simply check if the hash has an Undef value for that key.

  $openvpnConf['compress'] == undef

The stdlib module has a function named has_key() that you can use which
checks if the key is present and returns true even if value is set to undef. If it really does not matter to you if key is set to undef or simply missing it is enough to check if you get an undef value back.

If you are asking how you lookup a key to see if it is in hiera - call
the lookup() function and use an undef default - then check if value was undef.

Hope that helps.
- henrik

Thank you.



--

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/piqkjf%24si1%241%40blaine.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to