If you're assigning $role inside the role::nameserver class, then its scope is limited to just role::nameserver (and any classes
that inherit from role::nameserver)[1]. So, hiera lookups from inside role::nameserver will see that level of your hierarchy, but
it will be invisible almost everywhere else. I say "almost" because if you have some other class or defined type that just happens
to assign a value to a local variable named $role, hiera lookups from within its scope will see that as well, which can lead to
all sorts of fun. That's why the hiera docs caution against using local variables to define your hierarchy[2].
If I understand correctly, what you're really trying to achieve here is to be able to use a node's "role name" in your hierarchy, yes?
For that, you really want a variable up at top scope, but how to set it? How are you associating your role classes with your nodes?
If you're using an ENC, you could have it return the role variable assignment (variables set in the ENC are included in top scope).
-Mike
[1]
http://docs.puppetlabs.com/puppet/3/reference/lang_scope.html[2]
http://docs.puppetlabs.com/hiera/1/puppet.html#best-practices