This message was deleted.
# puppet
s
This message was deleted.
j
Ok, how do i create an alias. Is that a puppet or hiera thing ?
h
A hiera thing -
my_common_key: "%{alias("module::key")}
see "interpolation syntax" and "alias" in the puppet documentation for hiera.
j
Ok, By my understanding, i still need to use the full name ( module::key )in the puppet recipe , correct ?
h
If you do this aliasing then you can lookup the key
my_common_key
in the example I showed.
If that is what you want to do - i.e. have an alias and thereby hiding the fact that the value comes from a particular module to make all the logic where you want to look up this value unaware of that it is actually defined in a module.
Otherwise, if the direct dependency on your module holding the data is ok, then just lookup that key. Some frown on such a design.
Other prefer to use a class, and have automatic lookup. Then, instead of doing lookups where the value is needed a simple reference to a variable is used.
$my_module::myclass::my_key
j
Ok, i see what you mean : my problem here is more like : the module does not bring any data at all, and i dont want it to. What i want is that at every level of hiera (node, role, common etc) the data in this key is append to the key. In the end , my module simply grab the key with a lookup and use all the values in this key. My problem is that without this value, my tests are failing. I am trying to stub this.
The 'dirty way' would be something like this : lookup('mykey',Hash,deep,lookup('mymodule:mykey'))
h
Sorry, can’t help you with how to stub this in a test.
j
No worries, thanks for your time anyway !
h
There should be people online later to help you with how to stub/mock hiera data.
However, if your modules referred to a variable instead of doing an explicit lookup, I think it would be easier to mock.
y
merge options can be configured in hiera IIRC
so no need to to explicit
lookup()
call
then, you can always use another hiera config for tests with
let(:hiera_config) { 'path/to/hiera.yaml' }
IIRC
what’s nice with APL - you don’t need to stub this.. just pass some example params with
let(:params) { { mykey => { ... } } }
another crazy idea is to use lookup() as a default value for the parameter.. though it’s almost the same as APL (except you don’t need to configure merge behaviour in Hiera)
h
@Yury Bushmelev having a lookup of a different key as the default is meaningfull, but not if trying to lookup the key that APL will lookup - APL will win in that case.
👍🏻 1