How to map an array within a resource

asked 2016-09-20 20:34:52 -0500

RobertII gravatar image

I've got stuck trying to use Puppet 3.8 to tackle what seems like it should be a simple problem.

My nodes have a number of independent installations of a single system. I have defined a top-level type which creates instances of many resources. My nodes then declare a number of instances, and all the resources are instantiated, just as I'd like.

Now, I'd like to augment each installation with its own set of externally node-specified directories.

So when my node declares...

installation { "user1": 
    subdirs => ["subdir1", "subdir2"] 

I'd like to end up creating (say)


How do I do that? In particular, how (within the class) do I transform the list of subdirectory names

["subdir1", "subdir2"] 

into names that are unique to the instance of the class, such as

 ["installation1/$subdir1", "installation1/$subdir2" ]
edit retag flag offensive close merge delete


Hi Robert, I am not very clear on this picture. But it seems you would need to have custom resource "defines" to be called from your resource. This defines will take the arguments like user and array of subdir where you can loop over your array to have the directory created.

rajeevsharma gravatar imagerajeevsharma ( 2016-09-21 01:08:04 -0500 )edit

Use PP 4.x (or PP 3.8 with the future parser). The keyword you're looking for is “lambdas” (for-loop iteration).

Kai Burghardt gravatar imageKai Burghardt ( 2016-09-21 07:16:32 -0500 )edit