On Sunday, January 26, 2014 7:13:51 AM UTC-6, thbe wrote:
>
> Hi @all,
>
> I try to pass a hash to a module class like this:
>
> class { 'modulename':
>   filecontent => {
>     name1 => 'value1',
>     name2 => 'value2',
>     ...
>     namex => 'valuex',
>   }
> }
>
> ​The class should take the hash list, loop over the list and create i.e. 
> file resources with namex and content valuex. What is the best way to do 
> this and, even more important, is it possible to do something like this?
>
>

Yes.  You can do it in a general way (i.e. without the restrictions in form 
imposed by create_resources()) by relying on array-titled resources.  You 
also need a function to extract the keys of a hash into an array, such as 
the keys() function available in PuppetLabs "stdlib" add-in module.  Then 
you do something like this:

class modulename ($filecontent) {
  $filenames = keys($filecontent)
  modulename::file { $filenames: }
}

define modulename::file () {
  $mycontent = $modulename::filecontent[$title]
  # do something with my content
}


John

-- 
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/6882b84f-453d-427c-9b69-cca547e71085%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to