I would like to collect a variable over different classes in Puppet. Is this possible?
For example, I want to assign two classes to a node:
class { "webapplication1": url => 'webapp1.example.com' }
class { "webapplication2": url => 'webapp2.example.com' }
Then I would like to include a different class, webserver
which sets up two virtual hosts for each of these two classes. Therefore it should get the two URL variables from both classes. I do not want to pass the URLs as parameters to the new class. For further fun, maybe sometimes I only want to add one class, or some other time I want to add a completely different class (all only with the similarity that they have a url parameter.
How can I collect these? I thought about adding a tag to each class and then collecting them via a resource collector (ok, does not work with classes). But how do I access their parameters?
So then I rather create a defined resource for webapplications, e.g.
webapplication { "webapplication1": url => 'webapp1.example.com' }
webapplication { "webapplication2": url => 'webapp2.example.com' }
But how would I then collect all urls from all webapplications?
Webapplication <| |>
This does not give me any functionality, it seems. Should I put a class around the webapplications
which will then create resources?
class webapps (
Hash $webapps,
) {
$webapps.each | String $appname, String $parameters | {
webapp { $appname:
* => $parameters,
}
apache::vhost { $parameters["url"]:
#...
}
}
}
class { webapps:
webapps => {
'webapplication1' = {
'url' => 'webapp1.example.com'
},
'webapplication2' = {
'url' => 'webapp2.example.com'
},
}
}
(not tested and might look simpler in YAML...). And tips how to start would be greatly appreciated. Just don't know how to nicely do this.
Thanks!