0

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

chugadie
  • 201
  • 1
  • 5

1 Answers1

1

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.

#in /etc/salt/master
ext_pillar:
  - file_tree:
      root_dir: /srv/salt/my-pillars/
      follow_dir_links: False
      raw_data: False

#on disk
/srv/salt/my-pillars/hosts/mydbserver/passwords.sls

https://docs.saltstack.com/en/latest/ref/pillar/all/salt.pillar.file_tree.html#module-salt.pillar.file_tree

chugadie
  • 201
  • 1
  • 5
  • Sorry for answering my own question, but I felt I was at my wit's end when I asked this question and I started pouring over all the module docs and found that the external pillar would solve my problem in a different way than what I was searching for. – chugadie Oct 30 '15 at 13:09