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

前端 未结 3 1211
小蘑菇
小蘑菇 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:36

    Alex's answer is great. The Salt Mine will give you the list of minions that's correct as of the last time the Mine was executed.

    If you want live up to the second data you can use the peer interface by using the publish module. Publish module docs are here: http://docs.saltstack.com/ref/modules/all/salt.modules.publish.html#module-salt.modules.publish

    {% for host in salt['publish.publish']('*', 'network.ip_addrs', 'eth0') %}
    [{{ host.fqdn }}]
        address {{ host.ip }}
        use_node_name yes
    {% endfor %}
    

    Make sure to set your master config to allow the minions to execute network.ip_addrs.

    EDIT:

    To answer a question below you must enable the host to query other minions through the peer publish interface. To allow all minions to query the ip addresses of all other minions, add this to your /etc/salt/master:

    peer:                                                                          
      .*:
        - network.ip_addrs
    

提交回复
热议问题