I have a custom module with a function that i can use in my states like this
{% set myvar = salt['mymodule.myfunction']() %}
Now I want/need to use it in my pillar. I have tried calling it the same way but I got an error
Jinja variable 'salt.loader.LazyLoader object' has no attribute 'mymodule.myfunction'
Is there any way to declare this module and function as valid in pillar?
Thanks
edit
The actual function is a simple regex to convert the minion ID to a short form of it. I finally implemented the actual functionality with Jinja in both states and pillar, and it works. I want to use it in states and pillar to be able to load a .sls file if it exists to override default setting with per-minion ones.
So my problem is actually solved but the question behind: how to have a (execution) module that can be loaded in states AND pillar, is still relevant i think. I may rename my question.
The pillar compilation happens on the master, not the minion. This means that modules only available in the
salt://...
tree (e.g. insalt://_modules
) cannot be used inside pillar files.In order to use the module in a pillar file, it must also be made available to the master. In the default configuration, this should be possible by copying the module to
/var/cache/salt/master/extmods/modules
. In order to avoid having to maintain the modules in two locations, one might simply add a symbol link:ln -s /srv/salt/_modules /var/cache/salt/master/extmods/modules
Depending on the values of the
extension_modules
andmodule_dirs
options in/etc/salt/master
, the actual path that has to be used might be different.This might not exactly be the right solution but there is a mechanism within Salt for generating pillar data by calling external pillar interfaces. Which allows you to use any information that is defined outside of salt. Note that you will need to updated the
ext_pillar
option in your salt-master config to configure theext_pillar
interface to run.For a full list of available ext_pillar functions see: https://github.com/saltstack/salt/tree/develop/salt/pillar