I would like to add some generic pillar data to minions based on roles, but also offer a way to customize each machine based on hostname (minion id).
In my pillar/top.sls file I have
base:
'*':
- pkgs/common-ubuntu-pkg
- fail2ban/config
'runit:True':
- runit/package
'is_virtual:True':
- users/vmuser
'role:database':
- match: grain
- mysql/defaults
And then I want to add something like this:
{% for host in pillar %}
'{{host}}':
include:
- {{host}}/passwords
{% endfor %}
Which works, but it only prints out 'master'. I'm using master-less salt-ssh, so I believe that's why the minions in the roster are not already in the pillar. I would like a different way to loop over defined minions, but I can't seem to easily get a view of what is in the salt dictionary.
{% for key in salt %}
'{{key}}':
include:
- foobar
{% endfor %}
Trying to debug using something like the above results in a KeyError
The solution relied not in using jinja in the pillar.top file, but using an external pillar plugin.
The external pillar plugin "file_tree" looks under a root_dir for directories hosts and nodegroups. Matching minion_ids as directories under root_dir/hosts/, it will add all .sls files as pillar data to that host/minion.
https://docs.saltstack.com/en/latest/ref/pillar/all/salt.pillar.file_tree.html#module-salt.pillar.file_tree