I have a parent class, a child class, and a defined type, like so: *init.pp*: class parent { create_resources(parent::versions, hiera(''versions'')) ... } *versions.pp:* define parent::versions($version) { } *child.pp*: class parent::child { include parent notify{ "${version}": } } (I''m omitting the hiera definition since I don''t think it relates to the issue). Basically, I''m trying to figure out how to access variables from a child class, that have been defined in the parent via create_resources. According to the documentation I read, I think this can be done: Variables and defaults declared in a local scope are only available in *that scope and its children* Clearly, I''m missing something here. I would expect this to print out the value of "$version", that is set by calling "create_resources" in the parent. Can someone correct me or point me in the right direction? Regards- JC -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CAFwM5Hxj6u8ht93OjEMwt8kzh1tEgiPJqttp%3D1a%3DH%3D%3DsR1w2ew%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
If I stick a "notify { "$version": }" into the define, it shows the expected value, so my issue appears to be scope access. On Sun, Nov 17, 2013 at 4:50 PM, Jay Christopherson <jc.listmail@gmail.com>wrote:> I have a parent class, a child class, and a defined type, like so: > > *init.pp*: > class parent { > create_resources(parent::versions, hiera(''versions'')) > ... > } > > *versions.pp:* > define parent::versions($version) { > } > > *child.pp*: > class parent::child { > include parent > > notify{ "${version}": } > } > > (I''m omitting the hiera definition since I don''t think it relates to the > issue). > > Basically, I''m trying to figure out how to access variables from a child > class, that have been defined in the parent via create_resources. > > According to the documentation I read, I think this can be done: > > Variables and defaults declared in a local scope are only available in *that > scope and its children* > > Clearly, I''m missing something here. I would expect this to print out the > value of "$version", that is set by calling "create_resources" in the > parent. > > Can someone correct me or point me in the right direction? > > Regards- > JC > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CAFwM5Hw0ye_kLnkoSXjNMcJHeKbc-HqdvNxNyzHVZhHNDVrABA%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Hi, On 11/18/2013 01:50 AM, Jay Christopherson wrote:> *versions.pp:* > define parent::versions($version) { > } > > *child.pp*: > class parent::child { > include parent > > notify{ "${version}": } > } > > Variables and defaults declared in a local scope are only available > in *that scope and its children* > * > * > Clearly, I''m missing something here. I would expect this to print out > the value of "$version", that is set by calling "create_resources" in > the parent.in this example, parent::child is *not* in fact a child of anything. It''s just a class in module called ''parent''. Seeing as $version is a parameter of a defined type of your''s, it doesn''t make sense to reference it anywhere else. Consider this: class test { parent::versions { "apache" => "2.2", ruby => "1.9.3" } notify { "$version": } } What would you expect $version to be in this context? Cheers, Felix -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/528A2B29.2090800%40alumni.tu-berlin.de. For more options, visit https://groups.google.com/groups/opt_out.
On Sunday, November 17, 2013 6:50:03 PM UTC-6, jc.listmail wrote:> > I have a parent class, a child class, and a defined type, like so: > > *init.pp*: > class parent { > create_resources(parent::versions, hiera(''versions'')) > ... > } > > *versions.pp:* > define parent::versions($version) { > } > > *child.pp*: > class parent::child { > include parent > > notify{ "${version}": } > } > > (I''m omitting the hiera definition since I don''t think it relates to the > issue). > > Basically, I''m trying to figure out how to access variables from a child > class, that have been defined in the parent via create_resources. > >You cannot by any means access parameters of declared resources from outside those resources, regardless of the mechanism by which those resources are declared. You can, however, access *class variables* from anywhere, provided that the class has been declared. Simply use the variable''s fully-qualified name, such as $parent::version.> According to the documentation I read, I think this can be done: > > Variables and defaults declared in a local scope are only available in *that > scope and its children* > >That statement appears to come from this doc: http://docs.puppetlabs.com/puppet/3/reference/lang_scope.html. I suggest you read the whole thing, but the bottom line for this case is that the only child scopes of class body local scopes are the bodies of other classes that inherit from it. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/009772b9-cf5c-4564-b8ad-1e5c881af60c%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.