Today looking for a solution to this I came up with a nice solution. I know 
this thread is old but I'm posting it just in case is useful for somebody:

on hiera.yaml:

:hierarchy:
  - 'host/%{::domain}/%{::hostname}'
  - 'domain/%{::domain}'
  - 'role/%{system_role}'
  - 'common'

on site.pp

node default {

  $system_role = get_system_role()

}

and get_system_role is a custom function:

require 'yaml'

module Puppet::Parser::Functions

  newfunction(:get_system_role, :type => :rvalue) do |args|

    hostname = lookupvar('fqdn')

    enc = %x[/etc/puppet/node.rb #{hostname}]

    yaml = YAML::load enc

    system_role = yaml['classes'].keys.first.scan(/::([a-z]*)/).flatten[0]


  end

end

This is asuming you use an ENC to assign classes like foreman / cobbler or 
pe

Cheers

Juan

On Saturday, February 16, 2013 5:00:59 AM UTC, Steve Roberts wrote:
>
>
> On Friday, February 15, 2013 6:37:10 AM UTC-8, jcbollinger wrote:
>>
>>
>>
>> On Thursday, February 14, 2013 1:45:36 PM UTC-6, Chad Huneycutt wrote:
>>>
>>> Thanks, John.  I think you are right that puppet should support it, 
>>> but I am pretty sure it does not.   I chatted with RI, and it seems 
>>> that the classname is not "exposed", so when the puppet backend does 
>>> the lookup, it figures out the classname and sets the 'calling_class' 
>>> variable before it interprets the hierarchy.  I am going to try to 
>>> hack the same thing into the yaml backend, as well as file a bug (or 
>>> +1 one) about it. 
>>>
>>>
>>
>> Yes, R.I. was explaining the current state of the code, as is also 
>> summarized in the PL bug tracker.  In addition to issue 14985, which we 
>> discussed above, there is http://projects.puppetlabs.com/issues/16730, 
>> which speaks directly to how %{calling_class} and %{calling_module} could 
>> be used in hiera.yaml in Puppet 2.7, whereas Puppet 3 apparently regressed 
>> on that.  That issue has been marked as a duplicate of 14985, however; I 
>> mention it to give you confidence about which issue to watch / vote up 
>> (14985).  Also to confirm that PL not only agrees that there's an issue, 
>> but has a solution in flight.
>>
>>
>>  
> This is very good to hear.  A few of weeks ago I was told about the 
> calling_* vars in #puppet IRC when I was looking to solve basically the 
> same sort of task.
>
> then  when I tried to use them this past weekend and it didn't work, I 
> asked in #puppet again if there was an issue, and folks acted like I was 
> crazy for thinking calling_{class,module} were supposed to work.
>
> Looking forward to having the issue resolved.
>  
>

-- 
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/be999593-f554-4e30-aab0-d75392a593a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to