As far as I know, this is not possible. Originally, Puppet used dynamic scoping for variables, but it was deprecated as of 2.7.0. See more information here about what you should do instead.
In this particular case, however, I don't think plain scoping will do. In fact, I think you should use either virtual resources or exported resources. They are both very similar, actually, except that exported resources work inter-hosts.
Either way, you'll just have to structure your code in a very different way than what you want to do, it seems to me. Spend some time looking at complex puppet modules and understand how they go about doing what they do.