Search code examples
salt-project

How to list salt minions by compound matching in template?


I would like to list all minions that match my compound targeting string. I have already looked at this question How to get a list of all salt minions in a template? but my question is a little bit different as I need to use compound matching. Also I may be hitting this bug: https://github.com/saltstack/salt/issues/18878

Take as example below template:

{% for host in salt['publish.publish']('G@roles:hadoop_master', 'network.interfaces', expr_form='compound') %}
echo {{ host }}:
  cmd.run
{% endfor %}

The problem is that it's not showing any data.

While the following template is working as expected:

{% for host in salt['publish.publish']('*', 'network.interfaces') %}
echo {{ host }}:
  cmd.run
{% endfor %}

I have also tried using the mine:

{% for host, hostinfo in salt['mine.get']('G@roles:hadoop_master', 'network.interfaces', 'compound').items() %}
echo {{ host }}:
  cmd.run
{% endfor %}

I have done all nessecary prequisites to setup mine and peer/publish. This is enabled on master /etc/salt/master:

peer:
  .*:
    - network.ip_addrs
    - network.interfaces

And following config is on minion /etc/salt/minion:

mine_functions:
    network.interfaces: []
    network.ip_addrs: []
    grains.items: []

Solution

  • Quoting the answer from whiteinge https://github.com/saltstack/salt/issues/18878#issuecomment-66865740:

    Compound matching for Mine and Peer was disabled in 2014.7.0 and will be re-enabled in 2014.7.1. See the note at the top of the release notes:

    http://docs.saltstack.com/en/latest/topics/releases/2014.7.0.html