How to get a list of all salt minions in a template?

前端 未结 3 1241
小蘑菇
小蘑菇 2020-12-13 20:55

Basically I am creating a Salt state describing Munin server configuration and I need to get a list of all minions known to the master, something like this:

         


        
3条回答
  •  难免孤独
    2020-12-13 21:24

    I managed to achieve this using Salt Mine system (thanks to members of Salt-users Google group):

    {% for host, hostinfo in salt['mine.get']('*', 'network.interfaces').items() %}
    [{{ host }}]
        address {{ hostinfo['eth0']['inet'][0]['address'] if hostinfo['eth0'].has_key('inet') else hostinfo['br0']['inet'][0]['address'] }}
        use_node_name yes
    {% endfor %}
    

    I had to add

    mine_functions:
      network.interfaces: []
    

    to the end of /etc/salt/minion on every node to enable Salt Mine.

提交回复
热议问题