It depends on what you mean by "like that". In the first place, you cannot have duplicate keys in hiera, and cannot have the same class appearing more than once in any node's catalog. In the second place, the Hiera keys used with automated binding of class parameter values are determined by the class and parameter names; you are not at liberty to choose arbitrary names.
If your objective is to manage multiple files via class 'protest', then you could rewrite it something like this (requires the future parser and the "stdlib" module; untested):
class protest (
$files = [],
$default_logdir = $protest::params::logdir,
$default_logfile = $protest::params::logfile,
$default_text = $protest::params::text
) inherits protest::params {
# need to generate full file names from (dir, name) pairs
# it's helpful to also fill in default values here
$full_filedata = $files.map() |$filedata| {
{
path => join([
(haskey($filedata, 'logdir') ? { true => $filedata['logdir'], default => $default_logdir}),
(haskey($filedata, 'logfile') ? { true => $filedata['logfile'], default => $default_logfile})
], ''),
text => (haskey($filedata, 'text') ? { true => $filedata['text'], default => $default_text})
}
}
$full_filedata.each() |$file| {
file { $file['path']:
ensure => 'file',
# no need for an inline template just to interpolate a variable's value:
content => "${file['text']}\n",
}
}
}
The data to go with this would need to be structured like so:
protest::files:
- logdir: '/tmp/'
logfile: fred1
text: 'Alfredo1 was here'
- logdir: '/tmp/'
logfile: fred2
text: 'Alfredo2 was here'
protest::default_logdir: '/tmp/'
protest::default_file: 'log'
protest::default_text: ''
This example goes to considerable effort to preserve the multiple levels of default values afforded by your original code, but it may be that that is unneeded, in which case the class could be simplified, and maybe the data, too.
On the other hand, this class does no data validation whatever. A robust implementation would check the input data and fail with a meaningful diagnostic in the even that the data were not structured correctly or had inappropriate values.
John