# Keys automatisch aufräumen

Wenn Sie eine virtuelle Maschine per `salt-cloud -d <MINION_ID>` löschen, wird der Key des Minions nicht automatisch aus der Key-Verwaltung gelöscht. `salt-key -L` zeigt alle alten Keys weiterhin an.

Abhilfe schafft hier der Salt-Reactor, welche auf den Befehlt `salt-cloud -d` (Deprovisionieren) reagieren kann.&#x20;

Legen Sie eine Reactor-Konfiguration an, oder ergänzen Sie eine ggf. Vorhandene.

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

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

{% endcode %}

{% hint style="info" %}
Änderungen am Reactor erfordern einen Neustart des Masters.&#x20;
{% endhint %}

Geben Sie an, was der Reactor bei "Cloud Destroy" tun soll.

{% 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 %}


---

# Agent Instructions: 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:

```
GET https://thorstenkramm.gitbook.io/saltstack/salt-cloud/keys-automatisch-aufraeumen.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
