Thanks John for your very interesting reply. On Tuesday, November 6, 2012 4:13:03 PM UTC-5, jcbollinger wrote: > > > > 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, >> } >> > > > There are other advantages to using 'include', too, so bravo! > > >> >> However, AFAIK there is no such feature as auto looking parameters for >> defined >> type. >> A common case is multiple vhost in Apache. >> > > > You already started answering your own question when you wrote > "multiple". For a similar feature to work for defined types, it has to be > able to identify keys to use to lookup parameters for a given instance, > preferably without risk of colliding with classes or other defined-type > instances. >
Actually the point was that the first key would be the defined type, which then has a "subkey" for each instance. There is a risk of collision between defined type and class names, but that is already the case within Puppet language anyway. > > >> >> Even though you can have apache installed as simply as "include apache", >> you >> still have a lot of define (one per vhost), possibly each with different >> parameters. >> >> Would it be possible to have hiera looking up for a hash of parameters. >> >> Something like this in hiera: >> >> --- >> apache_vhost: >> website1: >> web_param1: 'foo' >> web_param2: 'bar' >> website2: >> web_param1: 'another_foor' >> web_param2: 'another_bar' >> >> And in the manifest, this would be invoked as simply as: >> >> node "test" { >> include apache >> apache_vhost { 'website1': } >> apache_vhost { 'website2': } >> } >> >> Any ideas on this ? Any plans of implementation ? >> > > > 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#createresourcesfor > more information. > This sound quite perfect for me, I'll give it a try ! Bruno -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/sX8vRr5WLkcJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.