# Salt SSH

## Salt im Push Modus mit SSH

Salt-SSH benutzte nur SSH zum Verteilen und »ausführen« der Sates. Eine Installation der Minion-Software auf den Zielsystemen ist nicht notwendig.

### Salt-SSH installieren

Salt-SSH gehört nicht zum Standard-Umfang vom Salt-Master und muss mit `apt install salt-ssh` nachinstalliert werden.

### Inventar anlegen

`/etc/salt/roster`

{% code title="/etc/salt/roster" %}

```
web1:
  host: 192.168.42.1 # The IP addr or DNS hostname
  user: fred # Remote executions will be executed as user fred
  passwd: foobarbaz # The password to use for login, if omitted, keys are used
  sudo: True # Whether to sudo to root, not enabled by default
  priv: ~/.ssh/id_ed25519
web2:
  host: 192.168.42.2
```

{% endcode %}

{% hint style="info" %}
Sollte der Root-User des Salt-Masters noch kein SSH-Key-Paar haben, generieren Sie eines mit dem Kommando `ssh-keygen -N "" -t ed25519 -C "root@salt-master.local"` .
{% endhint %}

### Problem: Python fehlt

Auf einem minimal installieren System kann es passieren, dass Salt SSH auf der Gegenseite keine oder ein nicht ausreichend aktuelle Python Version installiert ist.

```
root@master:~# salt-ssh box1 test.ping
[ERROR   ] Failed collecting tops for Python binary python3.
[ERROR   ] ERROR: Failure deploying thin, retrying:
STDOUT:

STDERR:

RETCODE: 10
box1:
    ----------
    retcode:
        10
    stderr:
    stdout:
        ERROR: Python version error. Recommendation(s) follow:
        Install Python 2.6 / Python 3 Salt dependencies on the Salt SSH master 
        to interact with Python 2.6 / Python 3 targets
```

![Python fehlt :-(](https://3666581685-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LFRZJPZX11pwB1staCp%2F-LbEjTeb39mkrc_cbJVU%2F-LbEm-iBe57T5-DtYHg4%2Fimage.png?alt=media\&token=717d4e93-e22b-4c9a-bb21-f925e2e96382)

#### Lösung

Über den sogenannten Raw-Modus, können Kommandos auch ohne Python ausgeführt werden, etwa die Installation von Python.&#x20;

```
# Debian/Ubuntu
salt-ssh <MINION-ID> -r 'sudo apt-get update; sudo apt-get -y install python3-minimal'
# Suse
salt-ssh <MINION-ID> -r "zypper --non-interactive install -y openssh-clients python3"
# RedHat
salt-ssh <MINION-ID> -r "yum -y install python3"
```

### Key automatisch akzeptieren

Wenn Sie viele Hosts per Salt SSH verwalten, möchten Sie nicht zu jedem Host eine manuelle SSH-Verbindung aufbauen, um den Fingerprint in der Know-Hosts-Datei zu speichern.\
Abhilfe schafft eine SSH-Client-Einstellung:

{% code title="/root/.ssh/config " %}

```
StrictHostKeyChecking no
```

{% endcode %}

### Defaults setzen

Anstatt für jeden Host in der Roster-Datei den Usernamen und den Port für die SSH-Verbindung zu setzen, können Sie auch den globalen Default ändern.

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

```yaml
ssh_sudo: False
ssh_timeout: 60
ssh_user: root
ssh_use_home_key: True
roster_defaults:
  priv: /root/.ssh/id_ed25519
```

{% endcode %}

Für alle weiteren SSH-Default-Werte siehe `grep ssh /etc/salt/master`.
