How do I build resource attribute array dynamically?

asked 2016-05-10 11:38:08 -0600

Czz gravatar image

updated 2016-05-12 03:14:50 -0600

I have an array of hashes like this:

$dirs => [
    {name => "one", <other settings>},
    {name => "two", <other settings>},
    {name => "anotherone", <other settings>},

Now I'm trying to use puppetlabs apache module vhost like this:

apache::vhost {"vhost name":
    servername => "servername",
    ip => "",
    port => '80',
    directories => [
        {path => "/static/path", provider => "location", <some other settings here> }

But the thing is, that I need to extend the directories property array with the extra "dynamic" elements generated from $dirs where the required settings would be created based on individual $dirs hashes + some common defaults. For example:

{path => "/dynamic/$name", provider => "location", <other stuff>}

I'd say I either need to construct the directories first (including the "static" one) and just give that to apache::vhost or extend the declaration with some resource collector, but I'm not sure how to go about that in either case..

Can someone point me to proper direction? (I'm using Puppet 4)

edit retag flag offensive close merge delete


There are a couple of ways it could be done. What version of puppet are you using? 3.x or 4.x? You can always create a custom function to do what you need in ruby, and assign that value back to the path variable after your transformation. You also may need to use a custom define .

DarylW gravatar imageDarylW ( 2016-05-11 22:13:45 -0600 )edit

We're using puppet 4.x (updated the question post)

Czz gravatar imageCzz ( 2016-05-12 03:18:31 -0600 )edit