Interesting question. I looked into the code and it looks like the grain loader does not recurse through directories. You can supply a grains_dir
option in your minion config as an extra place to look for grains which may get you what you're looking for.
Grain loading
SaltStack grains use the following precedence scheme for loading grains.
- Core grains (this is stuff like the
os
grain where SaltStack derives info from the system itself).
- Custom grains in
/etc/salt/grains
(YAML file you could add custome grains to).
- Custom grains in
/etc/salt/minion
(the minion config file).
- Custom grain modules in _grains directory, synced to minions.
Dynamic grains (EC2 example)
You could use something to dynamically set the grains for a minion, a good example of this is the ec2_tags grains module which basically makes a grain based on EC2 tags assigned to the instance.