On Fri, Jul 13, 2018 at 03:44:04PM +0000, Helmut Schneider wrote:
> Christopher Wood wrote:
> 
> > Have you considered switching to an EPP template? You can limit the
> > data passed in to only valid types (otherwise catalog compilation
> > failure), it's quite useful.
> 
> Not yet. And I'm not sure if that will help. In my case there are
> commands with and without parameters:
> 
> proto udp
> dev tun
> persist-tun
> nobind

This still sounds like a data validation item quite doable with types.

https://puppet.com/docs/puppet/5.5/lang_data_hash.html#the-hash-data-type

Hash[Enum['proto', 'dev'], String]
Hash[Enum['proto', 'dev'], Variant[String, Undef]]

> So even if I pass only specific ones I still have to check if there is
> a corresponding value for the key, otherwise
> 
> <%= key %> <%= value %>
> 
> will fail.

However the odd thing is that I am unable to reproduce what you are seeing with 
a plain undef in a very simple case. The undef is not stringified for me in 
puppet 5.4.0.


$ cat /tmp/x.pp
$x = { 'a' => undef }
$c = template('/tmp/t.erb')
notice($c)
$ cat /tmp/t.erb 
a is <%= @x[0] %>
$ puppet apply /tmp/x.pp 
Notice: Scope(Class[main]): a is 

Notice: Compiled catalog for cwl in environment production in 0.03 seconds
Notice: Applied catalog in 0.16 seconds


Possibly is_a? might help in this case if you need the erb for flexibility. 
Very simplistically and untested:

<%= key %><%= if value.is_a? String then " = #{value}" end %>
<%= key %><%= if value.is_a? Array then " = #{value.sort.join(' ')}" end %>

Then if you see the undef appear in your output file you will know it exists in 
the yaml as one of these specific data types.

-- 
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/20180713162532.4tqgcymyurwtt6fh%40iniquitous.heresiarch.ca.
For more options, visit https://groups.google.com/d/optout.

Reply via email to