Skip to content

[BUG] minion crashes when empty grains are supplied as minion config #61321

Closed

Description

@margau

Description
The minion crashes when an empty grains-dict is supplied with the minion config:

Dec 03 08:16:41 hostname systemd[1]: Starting The Salt Minion...
Dec 03 08:16:41 hostname systemd[1]: Started The Salt Minion.
Dec 03 08:16:41 hostname salt-minion[80365]: [ERROR   ] 'NoneType' object is not iterable
Dec 03 08:16:41 hostname salt-minion[80365]: Traceback (most recent call last):
Dec 03 08:16:41 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/utils/parsers.py", line 210, in parse_args
Dec 03 08:16:41 hostname salt-minion[80365]:     mixin_after_parsed_func(self)
Dec 03 08:16:41 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/utils/parsers.py", line 887, in __setup_extended_logging
Dec 03 08:16:41 hostname salt-minion[80365]:     log.setup_extended_logging(self.config)
Dec 03 08:16:41 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/log/setup.py", line 414, in setup_extended_logging
Dec 03 08:16:41 hostname salt-minion[80365]:     providers = salt.loader.log_handlers(opts)
Dec 03 08:16:41 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/loader/__init__.py", line 685, in log_handlers
Dec 03 08:16:41 hostname salt-minion[80365]:     ret = LazyLoader(
Dec 03 08:16:41 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 255, in __init__
Dec 03 08:16:41 hostname salt-minion[80365]:     self.opts = self.__prep_mod_opts(opts)
Dec 03 08:16:41 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 573, in __prep_mod_opts
Dec 03 08:16:41 hostname salt-minion[80365]:     self.pack["__grains__"] = salt.utils.context.NamespacedDictWrapper(
Dec 03 08:16:41 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/utils/context.py", line 203, in __init__
Dec 03 08:16:41 hostname salt-minion[80365]:     super().__init__(self._dict())
Dec 03 08:16:41 hostname salt-minion[80365]: TypeError: 'NoneType' object is not iterable
Dec 03 08:16:46 hostname salt-minion[80365]: Usage: salt-minion [options]
Dec 03 08:16:46 hostname salt-minion[80365]: salt-minion: error: Error while processing <function LogLevelMixIn.__setup_extended_logging at 0x7f5ef3f808b0>: Traceback (most recent call last):
Dec 03 08:16:46 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/utils/parsers.py", line 210, in parse_args
Dec 03 08:16:46 hostname salt-minion[80365]:     mixin_after_parsed_func(self)
Dec 03 08:16:46 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/utils/parsers.py", line 887, in __setup_extended_logging
Dec 03 08:16:46 hostname salt-minion[80365]:     log.setup_extended_logging(self.config)
Dec 03 08:16:46 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/log/setup.py", line 414, in setup_extended_logging
Dec 03 08:16:46 hostname salt-minion[80365]:     providers = salt.loader.log_handlers(opts)
Dec 03 08:16:46 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/loader/__init__.py", line 685, in log_handlers
Dec 03 08:16:46 hostname salt-minion[80365]:     ret = LazyLoader(
Dec 03 08:16:46 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 255, in __init__
Dec 03 08:16:46 hostname salt-minion[80365]:     self.opts = self.__prep_mod_opts(opts)
Dec 03 08:16:46 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 573, in __prep_mod_opts
Dec 03 08:16:46 hostname salt-minion[80365]:     self.pack["__grains__"] = salt.utils.context.NamespacedDictWrapper(
Dec 03 08:16:46 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/utils/context.py", line 203, in __init__
Dec 03 08:16:46 hostname salt-minion[80365]:     super().__init__(self._dict())
Dec 03 08:16:46 hostname salt-minion[80365]: TypeError: 'NoneType' object is not iterable
Dec 03 08:16:46 hostname systemd[1]: salt-minion.service: Main process exited, code=exited, status=64/USAGE
Dec 03 08:16:46 hostname systemd[1]: salt-minion.service: Failed with result 'exit-code'.

If the grain configuration is removed or provided with content, the issue is gone.
When the configuration is automatically created/templated, it is possible that grains: is empty on some minions, depending on the used setup.

Setup
Salt-Master and Minion on the same machine (EC2) under ubuntu 20.04.
Minion configuration contains:

cat /etc/salt/minion.d/grains.conf 
grains:

Steps to Reproduce the behavior
Add a minion config, e.g. in /etc/salt/minion.d/grains.conf, with an empty grains dict:

grains:

The minion crashes upon restart.

Expected behavior
The minion should not crash, just ignore the grains configuration.

Versions Report
Both master and minion have the same version out of the https://repo.saltproject.io/py3/ubuntu/20.04/amd64/latest focal main repository.

salt --versions-report
Salt Version:
          Salt: 3004
 
Dependency Versions:
          cffi: Not Installed
      cherrypy: Not Installed
      dateutil: 2.8.2
     docker-py: Not Installed
         gitdb: 2.0.6
     gitpython: 3.0.7
        Jinja2: 2.10.1
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 0.6.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: Not Installed
      pycrypto: Not Installed
  pycryptodome: 3.6.1
        pygit2: Not Installed
        Python: 3.8.10 (default, Sep 28 2021, 16:10:42)
  python-gnupg: 0.4.5
        PyYAML: 5.4.1
         PyZMQ: 18.1.1
         smmap: 2.0.5
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.2
 
System Versions:
          dist: ubuntu 20.04 focal
        locale: utf-8
       machine: x86_64
       release: 5.11.0-1022-aws
        system: Linux
       version: Ubuntu 20.04 focal

Activity

  1. added
    bug
    on Dec 3, 2021
  2. OrangeDog commented on Dec 3, 2021

    @OrangeDog
    Contributor

    IMO that's invalid config (and not a bug). To actually express empty grains configuration it should be grains: {}.

  3. margau commented on Dec 3, 2021

    @margau
    Author

    Yes, this can be seen as invalid config. However, it should either catch and ignore/warn about the invalid config, or at least fail with a reasonable log like "Invalid config 'grains is NoneType, dict expected in file, line'.

  4. added
    pending-discussion
    on Dec 3, 2021
  5. waynew commented on Dec 6, 2021

    @waynew
    Contributor

    @OrangeDog is correct that it's invalid config, and we should require grains: {}. That being said, @margau also is correct that we should either:

    a) catch & warn, or
    b) simply treat grains: None and grains: {} as equivalent.

    Though, this is also and extremely low priority bug - if anyone wants to pick it up and write a test/fix for this, that might be a good starter issue.

    Personally I lean towards "catch and warn" - though the catch actually shouldn't happen at this location -- it should happen earlier, when the grain file is actually loaded.

  6. added
    help-wanted
    and removed on Dec 6, 2021
  7. added this to the Approved milestone on Dec 6, 2021
  8. added
    severity-low
    and removed
    pending-discussion
    on Dec 6, 2021
  9. self-assigned this
    on Jul 22, 2026
  10. added a commit that references this issue on Jul 28, 2026
    3bb5529
  11. added a commit that references this issue on Aug 10, 2026
    c5e0804
  12. added a commit that references this issue on Aug 11, 2026
    9654b60
  13. BrianHa94 commented on Aug 11, 2026

    @BrianHa94
    Collaborator

    Fix has been merged. #69891

  14. added a commit that references this issue on Oct 27, 2026
    7c3f2fd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bughelp-wantedseverity-low

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions