Open mchugh19 opened 12 years ago
Figured out the error when using this backend with a module.
Since the mcollective facts are not added to hiera by default, when not run by the command line, the fqdn variable is not available.
Changing the line fqdn = scope['fqdn'] if scope.has_key?('fqdn') to fqdn = scope.catalog.tags[4]
to get the hostname from the normal scope corrects the error.
Another great find! I'll look into both of your suggestions after work tonight.
I'm curious about the scope.catalog.tags[4]
bit - can we count on that to always be at [4]
between versions, or is there a more canonical way to get at that data from within Hiera? We may have to check with some of the folks at PuppetLabs about how they approach this.
That's a great question, I have no idea. I stumbled across the catalog.tags bit in some puppet doc, then looked through the result to find that it was an array that included the fqdn. I sent a message asking the puppet user mailing list yesterday, but heard nothing back. So for now it seems to work, but I too would feel a whole lot better if it were a documented API. On Aug 10, 2012 8:03 PM, "Tray" notifications@github.com wrote:
I'm curious about the scope.catalog.tags[4] bit - can we count on that to always be at [4] between versions, or is there a more canonical way to get at that data from within Hiera? We may have to check with some of the folks at PuppetLabs about how they approach this.
— Reply to this email directly or view it on GitHubhttps://github.com/torrancew/hiera-foreman/issues/1#issuecomment-7663038.
So, it turns out that scope['fqdn'] is just fine, it's just that the "scope" object available in Puppet doesn't support has_key?, as it's not really a hash, just a wrapper around Puppet's internal Scope objects providing a hash-like accessor (). I'm working on a branch based off of your work now that I'm still touching up.
Great! I don't know where you managed to find that info. I had a heck of a time coming up with the seemingly hacky scope.catalog.tags bit :) Good work!
This issue seems to be closed :)
The last bits need to get flushed out for this to be a usable hiera backend from puppet. Currently when hiera is used inside of a module and attempts to query the foreman backend if fails with:
err: undefined method `has_key?' for #Hiera::Scope:0x7ffbdcb524f0 at /etc/puppet/modules/development/sshd/manifests/init.pp:10 on node NODENAME