Falkor
2011-Nov-15 13:07 UTC
[Puppet Users] Accessing definition parameter value out of scope
Hi everybody. i''m running Puppet 2.6.2 and I have the following problem. Assuming I have a definition toto::tutu instanced as follows: ------------------%< ------------------- define toto::tutu ($key = ''default_val'') { ... } toto::tutu { ''example1'': key => ''val1'' } toto::tutu { ''example2'': key => ''val2'' } ------------------------------------------ Is there now a way in another scope (for instance in the definition ''tata'' to access the value ''val2'' for instance? I was hoping that the syntax $val = Toto::Tutu[''exemple2''][key] would work but that''s not the case. Any suggestion? Note that the problem comes from the fact that I''m dealing here with definitions and not classes. Classes are uniquely defined (and instanced) such that I would then be able to access the value of the key parameter by toto::tutu::key (assuming of course I did not duplicate the instanciation). Thanks! -- 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-Nov-15 18:18 UTC
[Puppet Users] Re: Accessing definition parameter value out of scope
On Nov 15, 7:07 am, Falkor <sebastien.varre...@gmail.com> wrote:> Hi everybody. > > i''m running Puppet 2.6.2 and I have the following problem. > > Assuming I have a definition toto::tutu instanced as follows: > > ------------------%< ------------------- > define toto::tutu ($key = ''default_val'') { ... } > > toto::tutu { ''example1'': key => ''val1'' } > toto::tutu { ''example2'': key => ''val2'' } > ------------------------------------------ > > Is there now a way in another scope (for instance in the definition > ''tata'' to access the value ''val2'' for instance? > > I was hoping that the syntax > > $val = Toto::Tutu[''exemple2''][key] > > would work but that''s not the case. Any suggestion?To my knowledge, you cannot access variables of a defined type instance. I''m not sure they even exist outside the definition. What you can do is establish a source of truth outside the definition that the definition and all other interested parties draw on. That could be a variable in some shared lexical scope, a global or class variable, or external data accessed via extlookup() or hiera. That would be a pretty good design strategy even if you were using classes rather than definitions. 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.