> On Apr 17, 2018, at 6:56 PM, adam.gard...@magicmemories.com wrote: > > So, I'm aiming to have a method of interpolating Facter facts in Hiera data > files that works more or less exactly like the `scope` lookup function, > except that if the Facter fact is not defined, this interpolation should > result in Hiera moving on to the next hierarchy level as if the key were not > found, rather than simply interpolating an empty string. > > I've managed to make a rough hack of > https://github.com/puppetlabs/puppet/blob/master/lib/puppet/pops/lookup/interpolation.rb > that seems to accomplish what I'm looking for, but I'm not really sure how > to work with Puppet's test infrastructure, nor whether this is really an idea > the Puppet team would actually be interested in. > > My actual goal is to allow Jenkins to run the Puppet Agent on a CI node while > setting an environment variable such as `FACTER_myapp_version`, and have a > node-specific YAML file that reads `profile::myapp::version: > "%{maybe('facts.myapp_version')}"`, and thus allow Jenkins to control the > version of the app that gets deployed; at the same time, during a run which > doesn't set that particular environment variable I'd want Hiera to continue > looking in other hierarchy levels, not just say that profile::myapp::version > is an empty string. And, I do want to control this in Hiera if at all > possible, not using > `pick($facts['myapp_version'],lookup('profile::myapp::version'))` in puppet > code, or anything similar.
The `pick` approach would seem to be very straightforward, can you explain why that's not suitable for you? > > So, I have three questions: > Is there an easier way to accomplish this that I'm not seeing, with a custom > Hiera backend or something similar? > If not, is there a system for implementing custom interpolation functions as > anything other than a patch to the `interpolation_method` method in > lib/puppet/pops/lookup/interpolation.rb? (I couldn't find one, but that > doesn't mean one doesn't exist) > If not, would anyone actually be interested in a pull request for this? Just IMHO - conceptually, this approach feels very strange to me because it's effectively injecting client-side source of truth (facts) into server-side truth (hiera data). The natural place to figure out which should "win" is in Puppet code, where you can codify the business logic in an expressive way. Not to say it's not possible to get this to work. (Though I confess I don't know how) --eric0 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/611B0F04-1536-49DA-8178-F2DD7C056920%40puppet.com. For more options, visit https://groups.google.com/d/optout.