Call puppet resource with several parameters, several times

I have a simple puppet specific resource that looks like this:

define mything($number, $device, $otherthing) { file{"/place/${number}": ensure => directory } mount { "/place/${number}": device => $device, ensure => mounted, require => File["/place/${number}"] } file {"/place/${number}/${otherthing}": ensure => directory, require => Mount['/place/${number}'] } } 

I need to call this resource several times with different parameters, but I can’t figure out how to do this without repeating repeatedly calling mything() .

Ideally, I will have all the options to store in some kind of array, and then just call mything($array) , a little like this:

 $array = [ {number => 3, something => 'yes', otherthing => 'whatever'}, {number => 17, something => 'ooo', otherthing => 'text'}, {number => 4, something => 'no', otherthing => 'random'}, ] mything($array) 

But that does not work. I'm sure this will work if my resource took only one parameter, and I just had a flat array of values, but can I do the same with a few named parameters?

+6
source share
1 answer

This might work for your business. Instead of defining an array in a variable, make their parameters when calling the define type.

 define mything($number, $device, $otherthing) { file{"/place/${number}": ensure => directory } mount { "/place/${number}": device => $device, ensure => mounted, require => File["/place/${number}"] } file {"/place/${number}/${otherthing}": ensure => directory, require => Mount['/place/${number}'] } } mything { "k1" : number => "3", device => "Yes", otherthing => "Whatever"; "k2" : number => "17", device => "Noo", otherthing => "Text"; "k3" : number => "5", device => "Oui", otherthing => "ZIP"; } 

I have not tested everything that I tested is define and it works:

 define mything($number, $device, $otherthing){ notify{"$device is $number not $otherthing":} } 

Results:

 Mything[k1]/Notify[Yes is 3 not Whatever]/message: Mything[k2]/Notify[Noo is 17 not Text]/message: 
+7
source

Source: https://habr.com/ru/post/954663/


All Articles