Alessandro Franceschi
2011-Oct-27 11:29 UTC
[Puppet Users] Dynamically create arguments for a define (or parametrized class)
Maybe I''m asking too much, but is there a way to dynamically add resources in a define/parametrized class based on a variable (or hash) passed to a containing class/define? Something that when I call boo { "bah": options => { "optiona" => "valuea", "optionb" => "valueb", }, } gets this result (what follows is the wanted behaviour not the actual code of the boo define) define boo ( $options ) { bar { "name": optiona => valuea, optiona => valuea, } } Or a more general note, is it possible to manage dynamically the name and presence of arguments in a define? Any help or direction is welcomed. Al -- 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/-/5PkidQ_83E0J. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Henrik Lindberg
2011-Oct-27 15:03 UTC
Re: [Puppet Users] Dynamically create arguments for a define (or parametrized class)
Did you try something like: define boo($a="a", $b="b", $c="c") { bar { $title: a => $a, b => $b, c => $c, } } boo { ''the title'' : a => "a value", c => "c value" } - henrik On 10/27/11 1:29 PM, Alessandro Franceschi wrote:> Maybe I''m asking too much, but is there a way to dynamically add > resources in a define/parametrized class based on a variable (or hash) > passed to a containing class/define? > > Something that when I call > boo { "bah": > options => { > "optiona" => "valuea", > "optionb" => "valueb", > }, > } > > gets this result (what follows is the wanted behaviour not the actual > code of the boo define) > > define boo ( > $options > ) { > > bar { "name": > optiona => valuea, > optiona => valuea, > } > } > > Or a more general note, is it possible to manage dynamically the name > and presence of arguments in a define? > > Any help or direction is welcomed. > Al > > -- > 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/-/5PkidQ_83E0J. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en.-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Alexandre
2011-Oct-27 17:01 UTC
[Puppet Users] Re: Dynamically create arguments for a define (or parametrized class)
There is a function to dynamically create Puppet resources from a hash: createresources(): http://docs.puppetlabs.com/references/stable/function.html#createresources On 27 oct, 17:03, Henrik Lindberg <henrik.lindb...@cloudsmith.com> wrote:> Did you try something like: > > define boo($a="a", $b="b", $c="c") { > bar { $title: > a => $a, > b => $b, > c => $c, > } > > } > > boo { ''the title'' : a => "a value", c => "c value" } > > - henrik > > On 10/27/11 1:29 PM, Alessandro Franceschi wrote: > > > > > > > > > Maybe I''m asking too much, but is there a way to dynamically add > > resources in a define/parametrized class based on a variable (or hash) > > passed to a containing class/define? > > > Something that when I call > > boo { "bah": > > options => { > > "optiona" => "valuea", > > "optionb" => "valueb", > > }, > > } > > > gets this result (what follows is the wanted behaviour not the actual > > code of the boo define) > > > define boo ( > > $options > > ) { > > > bar { "name": > > optiona => valuea, > > optiona => valuea, > > } > > } > > > Or a more general note, is it possible to manage dynamically the name > > and presence of arguments in a define? > > > Any help or direction is welcomed. > > Al > > > -- > > 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/-/5PkidQ_83E0J. > > To post to this group, send email to puppet-users@googlegroups.com. > > To unsubscribe from this group, send email to > > puppet-users+unsubscribe@googlegroups.com. > > For more options, visit this group at > >http://groups.google.com/group/puppet-users?hl=en.-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Alessandro Franceschi
2011-Oct-27 17:43 UTC
Re: [Puppet Users] Dynamically create arguments for a define (or parametrized class)
On Thursday, October 27, 2011 4:03:42 PM UTC+1, Henrik Lindberg wrote:> > Did you try something like: > > define boo($a="a", $b="b", $c="c") { > bar { $title: > a => $a, > b => $b, > c => $c, > } > } > > boo { ''the title'' : a => "a value", c => "c value" } >Thanks for reply, Henrik What you''ve written works, but doesn''t fit my case. Taken your examples I don''t want (can''t) pre-define boo arguments. I would have something like: define boo($options) { bar { $title: a => $a, # this argument dynamically created according to $options (which is supposed to be an hash) b => $b, # as above c => $c, # as above } } I would use boo in this way: boo { "title": options { a => aa, b => bb, c => dfs, }, } ... (am I asking too much ? :-) -- 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/-/8ROd9Z11z2cJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Alessandro Franceschi
2011-Oct-27 17:46 UTC
[Puppet Users] Re: Dynamically create arguments for a define (or parametrized class)
Thanks for the link. I fear that this function doesn''t exactly apply to my case (it creates dynamically resources, not arguments for a resource) but I should give it a deeper look and consider if I can work around it. al -- 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/-/IRS5R_gfpk0J. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ken Barber
2011-Oct-27 17:51 UTC
Re: [Puppet Users] Re: Dynamically create arguments for a define (or parametrized class)
Yeah - nice one Henrik. Al - You should be able to create something based on create_resources to do what you want. Its a similar concept. ken. On Thu, Oct 27, 2011 at 6:46 PM, Alessandro Franceschi <al@lab42.it> wrote:> Thanks for the link. > I fear that this function doesn''t exactly apply to my case (it creates > dynamically resources, not arguments for a resource) but I should give it a > deeper look and consider if I can work around it. > al > > -- > 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/-/IRS5R_gfpk0J. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2011-Oct-28 16:01 UTC
[Puppet Users] Re: Dynamically create arguments for a define (or parametrized class)
On Oct 27, 12:43 pm, Alessandro Franceschi <a...@lab42.it> wrote:> I would have something like: > define boo($options) { > > bar { $title: > a => $a, # this argument dynamically created according to $options > (which is supposed to be an hash) > b => $b, # as above > c => $c, # as above > }} > > I would use boo in this way: > boo { "title": > options { > a => aa, > b => bb, > c => dfs, > }, > > } > > ... (am I asking too much ? :-)I suspect that your intention is not coming across well. Are you just asking how to get values out of a hash? For instance, what about this: define boo($options) { bar { $title: a => $options[''a''], b => $options[''b''], c => $options[''c''] } } boo { "title": options => { a => ''aa'', b => ''bb'', c => ''dfs'', } } Note that in that particular usage, create_resources() can replace definition ''boo'' altogether: create-resources(''bar'', { ''title'' => { ''a'' => ''aa'', ''b'' => ''bb'', ''c'' => ''cc'' }}) Note that the inner hash in that case is exactly what you were assigning to definition ''boo''s ''options'' parameter. This depends on the keys of the inner hash(es) all being names of parameters of the resource type ''bar''. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.