I finally did it my self.
For sure I hate Ruby.

This custom function will add values from arbitrary keys (must be arrays) 
at the beginning of "hierarchy"
For my example, I have just included hiera_hook("roles") in site.pp to 
achieve to behavior I described previously.


module Puppet::Parser::Functions
      newfunction(:hiera_hook) do |*args|
                require 'puppet/indirector/data_binding/hiera'
                require 'hiera'
                require 'hiera/scope'
                require 'puppet'

                key, default, override = HieraPuppet.parse_args(args)
                value=HieraPuppet.lookup(key, default, self, override, 
:priority)
                
hierarchy=Puppet::DataBinding::Hiera.hiera().config[:hierarchy]
                value.each do |val|
                        if not hierarchy.include?(val)
                                hierarchy.insert(0,val)
                        end
                end
      end
end



Le vendredi 2 mai 2014 16:11:51 UTC+2, Vincent Miszczak a écrit :
>
> Hi,
>
> I'd like to add things dynamically to :hierarchy: when I use hiera.
>
> I'd like to be able to do the following :
>
> in site.pp:
> hiera_roles()
>
> hiera_roles() would search in hiera for something like :
>
> mynode.yaml:
> roles:
>  - roles/appserver
>  - roles/databaseserver
>
> and I could have :
>
> roles/appserver.yaml:
> classes:
>  - appserver
>
>
> roles/databaseserver.yaml:
> classes:
>  - databaseserver
>
> So my node is not limited to one role, but to any number of roles I 
> decide. You know, sometime you have nodes acting as appservers or 
> databaseservers and sometimes they do both.
>
> Interpolation tokens in hiera.yaml could have been nice but arrays are not 
> properly expanded in context of hiera. 
> I've been looking at the code and this should be pretty straightforward to 
> do so but I really don't get how to write Ruby code. This looks over 
> complicated regarding other language I know such as Python/Java.
>
> I just want a custom function hiera_roles() append to the hierarchy array 
> used by Puppet.
>
> Could someone help with writing this custom function ?
>
> Regards,
>
> Vincent
>
>
>

-- 
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/6c4cf202-62ea-4c20-b927-75ac17c8a81f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to