On Monday, June 26, 2017 at 7:57:06 AM UTC-5, Prunk Dump wrote: > > Hello puppet Team ! > > I have trouble upgrading some code from puppet-3.7 to puppet-4.8. > > I have a class, a defined type, and a sub-defined type like this : > > [...]
> So there is two "mainclass::myress" declaration. Each one have a different > value of $myressvar inside the ressource. And each one declare one > "mainclass::myress::sub" ressource. In puppet 3.7 everything works just > like this. And > > -> In the "mainclass::myress::sub" déclared by "myressv1" I can access the > value of the "$myressvar" variable of the "myressv1" ressource just by > "$myressvar". So using the "$myressvar" variable inside > "mainclass::myress::sub" I get the value of the parent ressource. > > That's doubtful. What you describe should not work in Puppet 3.7 at all, neither with nor without the future parser. I did not even find a bug report that would explain why it might have seemed to work for you. Puppet 3.7's scoping rules are documented at https://docs.puppet.com/puppet/3.7/lang_scope.html. Those docs are substantially unchanged for all v4 releases so far, and as a matter of semantic versioning, I expect them to remain substantially unchanged for all remaining v4 releases. Note in particular that - "Code inside a class definition or defined type exists in a local scope." - "Variables and defaults declared in a local scope are only available in that scope and its children." - "Node scope and the local scopes created by defined resources are anonymous and cannot be directly referenced." - Although not a direct quote, the parent scope of every defined type's local scope is *node scope*, regardless of where that instance is declared. I could believe that the behavior you describe was exhibited by Puppet *2*.7, which had very different scoping rules for variables, but the scope change was one of the major differences between Puppet 2 and Puppet 3. Not only should what you describe not work in Puppet 3 (or 4), there is no way at all in v3 or v4 of the Puppet language to access the local variables of a defined type instance, though I believe there is a function available from the stdlib module for accessing their *parameters*. All that aside, the easiest solution is probably to give mainclass::myress::sub a parameter by which the wanted value from a mainclass::myress instance is provided to it. -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/86fe4f10-3936-43b8-b977-f333c96da5a5%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
