Repository navigation
Description
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
OrangeDog commentedon Dec 3, 2021
IMO that's invalid config (and not a bug). To actually express empty grains configuration it should be
grains: {}.margau commentedon Dec 3, 2021
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'.
waynew commentedon Dec 6, 2021
@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: Noneandgrains: {}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.
Fix minion crash when grains config option is empty
Widen empty-grains guard to any non-dict value
Add tests for empty-string grains config option
Fix minion crash on empty grains config option
Document required shape of grains config option
Fix minion crash when grains config option is empty
Fix minion crash when grains config option is empty
BrianHa94 commentedon Aug 11, 2026
Fix has been merged. #69891
Fix minion crash when grains config option is empty