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 On Friday, August 23, 2013 9:33:14 AM UTC-7, JeremyCampbell wrote: > > Eric, thanks. I've spent most of today trying to get this to work but I > have to submit again. I've read the linked docs on variables multiple > times. As I understand it, with Puppet you cannot assign top-level > variables i.e. starting with $::, these are reserved for facts and other > built in Puppet values. So I assign $role = "nameserver" in the > role::nameserver class - this works and I get no errors. However no matter > what I do hiera doesn't recognise the variable as shown below. > > - "%{::environment}/%{::clientcert}" > - "%{::clientcert}" > - "%{::environment} > - "%{role}" > - common > > Any ideas what could be causing this? > -- 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+unsubscr...@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.