We're using saltstack and like to write a custom grain which depends on a python library - netifaces in this case.
As all minions should be able to execute the grain we need to ensure that this library is always available.
What is best practice to achieve this? Is it recommended to just write a state and apply this state to all minions. It feels a bit messy to have a dependency between the grain and a state. Is there another way to define the dependency inside of the grains itself?
Grains are not responsible to manage their own dependencies. Based on this it seems straight forward to me to write a state that resolves the dependencies of a grain.
Grains shipped in saltstack/salt/salt/grains/core.py report about missing modules like that:
log = logging.getLogger(__name__)
HAS_WMI = False
if salt.utils.is_windows():
# attempt to import the python wmi module
# the Windows minion uses WMI for some of its grains
try:
import wmi # pylint: disable=import-error
import salt.utils.winapi
HAS_WMI = True
except ImportError:
log.exception(
'Unable to import Python wmi module, some core grains '
'will be missing'
)
Further opinions are welcome.