Hello

I recently came across a module where I had the following problem:

I have some arrays with OS specific defaults which get written into a config file via template. The user of the module may want to do one of the following things:

1. Use the default settings provided by the module
2. Completely overwrite the array
3. Append some values to the array from a hiera_array lookup
4. Overwrite the defaults and Append some values to the array from a hiera_array lookup

I wondered if there is an easy solution to this or an already established pattern. The code I came up with which implements all the requirements above looks something like this:

manifests/init.pp
class example (
$myvar = $example::params::myvar,
) inherits example::params {
  notify{$myvar: }
}

manifests/params.pp
class example::params {

  $myvar_defaults = [
    'some',
    'actual',
    'defaults',
  ]

  $myvar_real_defaults = hiera('example::myvar_defaults', $myvar_defaults)
  $myvar_append = hiera_array('example::myvar_append', [])
  $myvar = $myvar_real_defaults + $myvar_append
}

Here is how this works for the requirements:

1. Simply use the class
2. Completely overwrite by setting the class parameter example::myvar as usual 3. Values set in hiera for variable example::myvar_append will be appended to example::myvar 4. Setting example::myvar_defaults (priority lookup) will overwrite the defaults but still append example::myvar_append

Would be great if I can get some feedback on this. Is there a simpler solution I missed? Is this too confusing to be useful at all? Is there an already established pattern as a solution to this problem I should use instead?

Thanks in advance
Andreas

--
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/56CC26CE.7050303%40puzzle.ch.
For more options, visit https://groups.google.com/d/optout.

Reply via email to