Search code examples
salt-project

Saltstack exclude specific minions from run from reactor


I should exclude some sls from run

I use reactor to apply highstate when minions starts up, like this:

/etc/salt/master.d/reactor/start.sls:

reactor:                            # Master config section "reactor"                                                                                  
  - 'salt/minion/*/start':          # Match tag "salt/minion/*/start"
    - /srv/salt/reactor/start.sls        # Things to do when a minion starts

/srv/salt/reactor/start.sls:

highstate_run:
  local.state.apply:
    - tgt: {{ data['id'] }}

It works. But how to exclude some hosts e.g by name ?

I tried to use compounds in sub sls files. But unfortunately excluding in sls files does not work.


Solution

  • I would use [jinja][1] for this. For a simple example, if you want to exclude minion names that start with 'region1', you can do

    {% if not data['id'].startswith('region1') %}
    highstate_run:
      local.state.apply:
        - tgt: {{ data['id'] }}
    {% endif %}```
    
    
      [1]: https://docs.saltstack.com/en/latest/topics/jinja/index.html