On Tuesday, November 6, 2012 11:04:46 AM UTC-6, Bruno Leon wrote:
Hello,
since Puppet 3 hiera is doing auto variable lookup for classes, which in my
view makes the code much clearer simply because we can use
include foo
instead of
class { 'foo':
param1 => value,
param2 => value,
}
You can do something very like what you describe via the built-in create_resources() function. Given the data exactly as you structured it in your example, you could do this:
# load the vhost data as a hash of hashes
$vhost_data = hiera('apache_vhost')
# declare the apache_vhost instances
create_resources('apache_vhost', $vhost_data)
# (that's it)
See
http://docs.puppetlabs.com/references/3.0.0/function.html#createresources for more information.
Alternatively, you can write hiera lookups into your definition, either in addition to or instead of parameters. Or it can be more efficient to load hiera data into class variables, and have your definition pull it from there:
class apache::vhost_data {
$data = hiera('apache_vhost')
}
define apache::vhost_wrapper () {
include 'apache::vhost_data'
$data = $apache::vhost_data::data[$name]
apache_vhost { $name:
web_param1 => $data['web_param1'],
web_param2 => $data['web_param2']
}
}
John