> For the complete documentation index, see [llms.txt](https://thorstenkramm.gitbook.io/saltstack/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://thorstenkramm.gitbook.io/saltstack/salt-reactor.md).

# Salt Reactor

Der Salt Reactor ist ein Prozess, welcher auf dem Master läuft und auf Events der Minions reagiert. Sobald der Event-Listener ein Event registriert, für das eine Reaktion definiert wurde, wird diese auf einem Minion ausgeführt. Der Reactor kann auf Standard-Events, wie »Minion gestartet« oder frei definierte Events reagieren.

### Reactor aktivieren

Der Reactor wird über die Konfiguration des Masters aktiviert. Verwenden Sie dazu etwa die Datei `/etc/salt/master.d/reactor.conf`.

{% hint style="info" %}
Nach jeder Änderung am Reactor müssen Sie den Salt Master neu starten.
{% endhint %}

**Ein simples Beispiel**

{% code title="/etc/salt/master.d/reactor.conf" %}

```yaml
reactor:
  - 'salt/minion/*/start':           # EVENT -> Match tag "salt/minion/*/start"
    - /srv/reactor/minion-start.sls  # REACTION -> Things to do when a minion starts                      
  - 'dummy/foo/*':
    - /srv/reactor/dummy.sls
```

{% endcode %}

{% code title="/srv/reactor/dummy.sls" %}

```yaml
{% set list = tag.split('/') %}
dummy:
  local.cmd.run:
    - name: gaga
    - tgt: 'some-minion'
    - arg:
      - 'echo "{{ data['id'] }}: {{ list[2] }} . {{ tag }} {{ data | json() }}">/tmp/reactor.txt'
```

{% endcode %}

```
root@minion1: salt-call event.send 'dummy/foo/hamster'
```

Mit dem Kommando `salt-run state.event pretty=True` beobachten Sie live, welche Events an den Reactor gesendet werden.

### Salt-Keys aufräumen

{% code title="/etc/salt/master.d/reactor.conf " %}

```yaml
reactor: 
  - 'salt/cloud/*/destroying': 
    - '/srv/reactor/salt_cloud_destroy_keys.sls'
```

{% endcode %}

{% code title="/srv/reactor/salt\_cloud\_destroy\_keys.sls" %}

```yaml
{%- set tag_split = tag.split('/') %} 
{%- set minion_id = tag_split[2] %} 
salt_cloud_destroy_key_{{ minion_id }}: 
  wheel.key.delete: 
    - match: {{ minion_id }}
```

{% endcode %}

### State nach VM Deployment ausrollen

{% code title="/etc/salt/master.d/reactor.conf" %}

```yaml
reactor: 
  # Machine created
  - 'salt/cloud/*/created':
    - '/srv/reactor/startup_highstate.sls'
  # Machine destroyed
  - 'salt/cloud/*/destroying': 
    - '/srv/reactor/salt_cloud_destroy_keys.sls'
```

{% endcode %}

{% code title="/srv/reactor/startup\_highstate.sls" %}

```yaml
reactor_highstate:
  cmd.state.apply:
    - tgt: {{ data['name'] }}
    - args:
      - mods: init.vminit
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://thorstenkramm.gitbook.io/saltstack/salt-reactor.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
