1

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.

  • I'm interested in knowing exactly what that function does, and if a pillar is the proper place. – Halfgaar Aug 17 '16 at 7:25
  • Could you describe what you actually do when you say use it in your pillar? – FredFoo Sep 16 '16 at 3:37
1

The pillar compilation happens on the master, not the minion. This means that modules only available in the salt://... tree (e.g. in salt://_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 and module_dirs options in /etc/salt/master, the actual path that has to be used might be different.

  • Thanks for your answer. I understand why exec modules are not available in pillar, and even if this solution seems a little hacky it may still be a good one. We are currently in the process of moving to pillarstack, so if I need it I'll check if it still works. – daks Mar 1 '17 at 9:27
0

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 the ext_pillar interface to run.

For a full list of available ext_pillar functions see: https://github.com/saltstack/salt/tree/develop/salt/pillar

  • I know about ext_pillar and I don't think it solve my problem. I want to be able to call a Python execution module from both states and pillar. – daks Oct 6 '16 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.