Hiera custom backend not working

asked 2017-09-12 07:55:49 -0500

flobob gravatar image

Hey,

I'm trying to write a custom hiera backend for mongodb with PE2017-2. I found some working examples with hiera v3 but I'd like to use hiera v5.

So I've just wrote a kind of "hello world" for my 'lookup_key' backend function, in vain...

Here is my hiera configuration:

"/etc/puppetlabs/puppet/hiera.yaml":

---
version: 5
hierarchy:
  - name: "common data (MongoDB version)"
    lookup_key: mongodb
    paths: 
      - "node/%{trusted.certname}" 
      - "common"
    options:
      dbname: "hiera"
      collection: "config"
      host: "localhost"

Here is my custom lookup_key backend: "/etc/puppetlabs/code/environments/production/modules/mongo/lib/puppet/functions/mongodb.rb" :

Puppet::Functions.create_function(:mongodb) do 
  Puppet.warning("mongodb") 
  dispatch :mongodb do 
    param 'String[1]', :key 
    param 'Hash[String[1],Any]', :options 
    param 'Puppet::LookupContext', :context 
  end

  def mongodb(key, options, context) 
    Puppet.warning("Custom_lookup_key_mongodb_backend") 
    context.not_found 
    {} 
  end 
end

I used the 'lookup' function to solicit hiera and its custom backend but it does not appear to be called. Indeed, I have no "WARN" entries in 'puppetserver.log' despite 'Puppet.warning' calls...

I do not understand what I missed.

Thank you

edit retag flag offensive close merge delete