> 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-cloud/hetzner-cloud.md).

# Hetzner Cloud

### Hcloud für Python installieren

```
pip3 install hcloud
```

### SSH Schlüsselpaar erzeugen

```bash
mkdir /etc/salt/cloud.keys.d 
ssh-keygen -N "" -t ed25519 -C "salt@hetzner" \
-f /etc/salt/cloud.keys.d/hetzner
```

### Cloud-Account vorbereiten

Zuerst müssen Sie ein Projekt anlegen, innerhalb dessen die Cloud-VMs von Salt angelegt werden.

Wählen Sie das neu angelegte Projekt aus und klicken Sie auf der linken Seite die Sicherheitseinstellungen an (Schlüssel-Symbol). Fügen Sie dann den öffentlichen SSH Schlüssel aus der Datei `/etc/salt/cloud.keys.d/hetzner.pub` des Salt-Masters hinzu. Geben Sie dem Schlüssel einen Namen, z. B. `salt`. Auf diesen Namen werden Sie später refferenzieren.

Wählen Sie im Bereich »Sicherheit« oben den Reiter »API TOKENS« aus und generieren Sie einen neuen Token. Nennen Sie diesen z. B. »Salt-Master« und aktivieren Sie **Lese- und Schreibrechte**. Notieren Sie sich den erzeugten Token.

<div><figure><img src="/files/Hv9LVE5TMbCbTbZJl5GA" alt=""><figcaption><p>Projekt anlegen</p></figcaption></figure> <figure><img src="/files/tHt1vAQtdNBcf6U5AuPt" alt=""><figcaption><p>SSH Key</p></figcaption></figure> <figure><img src="/files/d3IBBQwm1spwoL7QFTKP" alt=""><figcaption><p>API Token</p></figcaption></figure></div>

### Konfigurationsdateien anlegen

Legen Sie einen Cloud-Provider an. Als `key` tragen Sie den zuvor generierten API Token ein.

{% code title="/etc/salt/cloud.providers.d/hetzner.conf" %}

```yaml
hetzner:
  key: <API-TOKEN>
  driver: hetzner
  private_key: /etc/salt/cloud.keys.d/hetzner
  ssh_keys:
    - salt       # Must match the key name as set on the Hetzner Conosle
  location: nbg1 # use 'salt-cloud --list-location hetzner' 
  minion:
    master: <FQDN-OR-IP-OF-MASTER>
    master_port: <MASTER-PORT>    # omit to use default 4506
    publish_port: <PUBLISH-PORT>  # omit to use default 4505
    tcp_keepalive_idle: 60
    tcp_keepalive_cnt: 2
    tcp_keepalive_intvl: 60

```

{% endcode %}

Testen Sie Konfiguration mit den folgenden Kommandos:

```
salt-cloud --list-images hetzner
salt-cloud --list-sizes hetzner
salt-cloud -f list_ssh_keys hetzner
```

Legen Sie anschließend Profile für die gewünschten VMs an. Beispiel:

```
ubuntu-s@hetzner:
  provider: hetzner
  image: ubuntu-22.04
  size: cx11
```

### VM verwalten

Legen Sie nun eine neue VM an

```
salt-cloud -p ubuntu-s@hetzner uriel -l debug
salt uriel test.ping
```

VM können mit `salt-cloud -d <MINION-ID>` wieder gelöscht werden.


---

# 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-cloud/hetzner-cloud.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.
