Bruno Leon
2011-Oct-03 22:44 UTC
[Puppet Users] Get the value of a parameter passed to a parameterized class
Hi, is there a way to get the value of a parameter passed to a parameterized class ? I''ve searched quite a lot and did not came out with a solution. Thanks -- Bruno -- 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.
Dan Bode
2011-Oct-03 22:51 UTC
Re: [Puppet Users] Get the value of a parameter passed to a parameterized class
This is stored inside of the compiled catalog. Catalogs are saved on the client where they are applied the default location is: /var/lib/puppet/client_yaml/catalog/CERTNAME.yaml On Mon, Oct 3, 2011 at 3:44 PM, Bruno Leon <nonolemono@gmail.com> wrote:> Hi, > > is there a way to get the value of a parameter passed to a parameterized > class ? > I''ve searched quite a lot and did not came out with a solution. > > Thanks > -- > Bruno > > -- > 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 <puppet-users%2Bunsubscribe@googlegroups.com>. > For more options, visit this group at http://groups.google.com/** > group/puppet-users?hl=en<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-04 13:11 UTC
[Puppet Users] Re: Get the value of a parameter passed to a parameterized class
On Oct 3, 5:44 pm, Bruno Leon <nonolem...@gmail.com> wrote:> Hi, > > is there a way to get the value of a parameter passed to a parameterized > class ? > I''ve searched quite a lot and did not came out with a solution.Did you mean within your manifests? You can do it easily as long as the class in question provides for it, otherwise not at all. For example: module1::class1($param1, $param2=''foo'') { $my_param1 = $param1 $my_param2 = $param2 } module2::class2 { notify { "module1::class1::param1": message => "module1::class1::param1 = $ {module1::class1::my_param1}" } notify { "module1::class1::param2": message => "module1::class1::param2 = $ {module1::class1::my_param2}" } } There, the class makes the parameters externally available by assigning their values to class variables. If you need parameter values from a class that does not expose them that way and that you cannot modify to do so, then you are out of luck. You can get something close, however: you can record the values that are *supposed* to be assigned in global variables or some other class''s variables. For example, module3::class3($param1, $param2=''foo'') { } module4::class4 { $class3_param1 = 42 $class3_param2 = ''bar'' class { "module3::class3": param1 => $class3_param1 param2 => $class3_param2 } } module5::class5 { notify { "module3::class3::param1": message => "module3::class3::param1 = $ {module4::class4::class3_param1}" } notify { "module3::class3::param2": message => "module3::class3::param2 = $ {module4::class4::class3_param2}" } } Good luck, 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.
Bruno Leon
2011-Oct-04 14:39 UTC
Re: [Puppet Users] Re: Get the value of a parameter passed to a parameterized class
On 11-10-04 09:11 AM, jcbollinger wrote:> > On Oct 3, 5:44 pm, Bruno Leon<nonolem...@gmail.com> wrote: >> Hi, >> >> is there a way to get the value of a parameter passed to a parameterized >> class ? >> I''ve searched quite a lot and did not came out with a solution. > Did you mean within your manifests? You can do it easily as long as > the class in question provides for it, otherwise not at all. For > example: > > module1::class1($param1, $param2=''foo'') { > $my_param1 = $param1 > $my_param2 = $param2 > } > > module2::class2 { > notify { "module1::class1::param1": > message => "module1::class1::param1 = $ > {module1::class1::my_param1}" > } > notify { "module1::class1::param2": > message => "module1::class1::param2 = $ > {module1::class1::my_param2}" > } > } > > There, the class makes the parameters externally available by > assigning their values to class variables. If you need parameter > values from a class that does not expose them that way and that you > cannot modify to do so, then you are out of luck. You can get > something close, however: you can record the values that are > *supposed* to be assigned in global variables or some other class''s > variables. For example, > > module3::class3($param1, $param2=''foo'') { > } > > module4::class4 { > $class3_param1 = 42 > $class3_param2 = ''bar'' > class { "module3::class3": > param1 => $class3_param1 > param2 => $class3_param2 > } > } > > module5::class5 { > notify { "module3::class3::param1": > message => "module3::class3::param1 = $ > {module4::class4::class3_param1}" > } > notify { "module3::class3::param2": > message => "module3::class3::param2 = $ > {module4::class4::class3_param2}" > } > } > > > Good luck, > > John >Very interesting ideas John. I did not thought about making the parameters available by assigning them to class variables. That would indeed work, but I was hoping for some kind of method that would allow to get the value, I also thought about passing every single parameter through hiera, so that they are easily available for any object, but that kind of end up having all variables/parameters in on place like it used to be in 0.25.X. I think I need to make up my mind about the best way to do this. Thanks a lot -- Bruno -- 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.
Bruno Leon
2011-Oct-04 14:40 UTC
Re: [Puppet Users] Get the value of a parameter passed to a parameterized class
I should have precised that I need them during the catalog compilation. Thanks -- Bruno On 11-10-03 06:51 PM, Dan Bode wrote:> This is stored inside of the compiled catalog. > > Catalogs are saved on the client where they are applied > > the default location is: > > /var/lib/puppet/client_yaml/catalog/CERTNAME.yaml > > On Mon, Oct 3, 2011 at 3:44 PM, Bruno Leon <nonolemono@gmail.com > <mailto:nonolemono@gmail.com>> wrote: > > Hi, > > is there a way to get the value of a parameter passed to a > parameterized class ? > I''ve searched quite a lot and did not came out with a solution. > > Thanks > -- > Bruno > > -- > 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 > <mailto:puppet-users@googlegroups.com>. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com > <mailto:puppet-users%2Bunsubscribe@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.-- 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-04 19:21 UTC
[Puppet Users] Re: Get the value of a parameter passed to a parameterized class
On Oct 4, 9:39 am, Bruno Leon <nonolem...@gmail.com> wrote:> On 11-10-04 09:11 AM, jcbollinger wrote: > > > > > > > On Oct 3, 5:44 pm, Bruno Leon<nonolem...@gmail.com> wrote: > >> Hi, > > >> is there a way to get the value of a parameter passed to a parameterized > >> class ? > >> I''ve searched quite a lot and did not came out with a solution. > > Did you mean within your manifests? You can do it easily as long as > > the class in question provides for it, otherwise not at all. For > > example: > > > module1::class1($param1, $param2=''foo'') { > > $my_param1 = $param1 > > $my_param2 = $param2 > > } > > > module2::class2 { > > notify { "module1::class1::param1": > > message => "module1::class1::param1 = $ > > {module1::class1::my_param1}" > > } > > notify { "module1::class1::param2": > > message => "module1::class1::param2 = $ > > {module1::class1::my_param2}" > > } > > } > > > There, the class makes the parameters externally available by > > assigning their values to class variables. If you need parameter > > values from a class that does not expose them that way and that you > > cannot modify to do so, then you are out of luck. You can get > > something close, however: you can record the values that are > > *supposed* to be assigned in global variables or some other class''s > > variables. For example, > > > module3::class3($param1, $param2=''foo'') { > > } > > > module4::class4 { > > $class3_param1 = 42 > > $class3_param2 = ''bar'' > > class { "module3::class3": > > param1 => $class3_param1 > > param2 => $class3_param2 > > } > > } > > > module5::class5 { > > notify { "module3::class3::param1": > > message => "module3::class3::param1 = $ > > {module4::class4::class3_param1}" > > } > > notify { "module3::class3::param2": > > message => "module3::class3::param2 = $ > > {module4::class4::class3_param2}" > > } > > } > > > Good luck, > > > John > > Very interesting ideas John. > > I did not thought about making the parameters available by assigning > them to class variables. > That would indeed work, but I was hoping for some kind of method that > would allow to get the value, > > I also thought about passing every single parameter through hiera, so > that they are easily available for any object, > but that kind of end up having all variables/parameters in on place like > it used to be in 0.25.X. > > I think I need to make up my mind about the best way to do this.If you are open to a design that uses non-parameterized classes instead of parameterized ones then I urge you to give it serious consideration. The main problem that parameterized classes address is not having all your data in one place. In fact, it''s exactly the opposite: having data in different (dynamic) scopes such that it is unclear from which one(s) classes are obtaining it. Although they provide one solution to that problem, parameterized classed introduce their own set of problems. Providing a central, universal data access point is exactly the purpose of hiera, and of extlookup() to a lesser extent. They -- especially hiera -- do not in fact require the data themselves to be collocated; instead, they allow your classes to get the needed data from wherever they happen to be. 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.