saltstack / saltstack/salt

[BUG] Not working grains lead to crashed salt-minon

Open
#68,075 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs-more-info needs-triage pending-discussion
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description
Hello,

I deployed a weird and not working custom grains.

but when i do this, saltstack runs "well" but cannot be restarted else, it will not start at all.

Steps to Reproduce the behavior

Jun 13 15:30:52 server systemd[1]: Started The Salt Minion.
Jun 13 15:30:53 server salt-minion[1064472]: [CRITICAL] Failed to load grains defined in grain file installed_packages.installed_packages in function <LoadedFunc name='installed_packages.installed_packages'>, error:
Jun 13 15:30:53 server salt-minion[1064472]: Traceback (most recent call last):
Jun 13 15:30:53 server salt-minion[1064472]:   File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/__init__.py", line 1188, in grains
Jun 13 15:30:53 server salt-minion[1064472]:     ret = funcs[key](**kwargs)
Jun 13 15:30:53 server salt-minion[1064472]:   File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 160, in __call__
Jun 13 15:30:53 server salt-minion[1064472]:     ret = self.loader.run(run_func, *args, **kwargs)
Jun 13 15:30:53 server salt-minion[1064472]:   File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1269, in run
Jun 13 15:30:53 server salt-minion[1064472]:     return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
Jun 13 15:30:53 server salt-minion[1064472]:   File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1284, in _run_as
Jun 13 15:30:53 server salt-minion[1064472]:     ret = _func_or_method(*args, **kwargs)
Jun 13 15:30:53 server salt-minion[1064472]:   File "/var/cache/salt/minion/extmods/grains/installed_packages.py", line 5, in installed_packages
Jun 13 15:30:53 server salt-minion[1064472]:   File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/pkgutil.py", line 157, in list_pkgs
Jun 13 15:30:53 server salt-minion[1064472]:     if "pkg.list_pkgs" in __context__ and kwargs.get("use_context", True):
Jun 13 15:30:53 server salt-minion[1064472]: NameError: name '__context__' is not defined
Jun 13 15:30:53 server salt-minion[1064472]: [CRITICAL] Failed to load grains defined in grain file installed_packages.installed_packages in function <LoadedFunc name='installed_packages.installed_packages'>, error:
Jun 13 15:30:53 server salt-minion[1064472]: Traceback (most recent call last):
Jun 13 15:30:53 server salt-minion[1064472]:   File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/__init__.py", line 1188, in grains
Jun 13 15:30:53 server salt-minion[1064472]:     ret = funcs[key](**kwargs)
Jun 13 15:30:53 server salt-minion[1064472]:   File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 160, in __call__
Jun 13 15:30:53 server salt-minion[1064472]:     ret = self.loader.run(run_func, *args, **kwargs)
Jun 13 15:30:53 server salt-minion[1064472]:   File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1269, in run
Jun 13 15:30:53 server salt-minion[1064472]:     return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
Jun 13 15:30:53 server salt-minion[1064472]:   File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1284, in _run_as
Jun 13 15:30:53 server salt-minion[1064472]:     ret = _func_or_method(*args, **kwargs)
Jun 13 15:30:53 server salt-minion[1064472]:   File "/var/cache/salt/minion/extmods/grains/installed_packages.py", line 5, in installed_packages
Jun 13 15:30:53 server salt-minion[1064472]:   File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/pkgutil.py", line 157, in list_pkgs
Jun 13 15:30:53 server salt-minion[1064472]:     if "pkg.list_pkgs" in __context__ and kwargs.get("use_context", True):
Jun 13 15:30:53 server salt-minion[1064472]: NameError: name '__context__' is not defined

Expected behavior
The customs grains cannot load, ok, but i need at least to have a minion which starts to permit redeployment of a fix.

Versions Report

[root@server ~]# salt-minion --versions-report
Salt Version:
          Salt: 3007.4
 
Python Version:
        Python: 3.10.17 (main, Jun  9 2025, 20:41:48) [GCC 11.2.0]
 
Dependency Versions:
          cffi: 1.16.0
      cherrypy: 18.8.0
  cryptography: 42.0.5
      dateutil: 2.8.2
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 3.1.6
       libgit2: Not Installed
  looseversion: 1.3.0
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.7
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     packaging: 24.0
     pycparser: 2.21
      pycrypto: Not Installed
  pycryptodome: 3.19.1
        pygit2: Not Installed
  python-gnupg: 0.5.2
        PyYAML: 6.0.1
         PyZMQ: 25.1.2
        relenv: 0.19.3
         smmap: Not Installed
       timelib: 0.3.0
       Tornado: 6.4.2
           ZMQ: 4.3.4
 
Salt Package Information:
  Package Type: onedir
 
System Versions:
          dist: rocky 9.5 Blue Onyx
        locale: utf-8
       machine: x86_64
       release: 5.14.0-503.23.2.el9_5.x86_64
        system: Linux
       version: Rocky Linux 9.5 Blue Onyx

Additional context
Add any other context about the problem here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with salt/loader/init.py and salt/modules/pkgutil.py, which appear in the traceback, and trace how exceptions from custom grains are handled during minion startup. Reproduce the failure with a grain that raises NameError; done means the minion starts despite the grain failing so the grain can be fixed or removed.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.