Pour revenir en arrière :

R4ROM09 - Outils de DevOps

2.1 / Prérequis

Il faut vérifier la version de python et install´e pip et paramiko

python3 --version
apt install python3-pip -y
apt install python3-paramiko

2.2 / Initier projet ssh-python

2.2.1 / Créer le projet

Depuis la VM (workdevops) Sur l’interface web de gitlab créer un projet ”ssh python” avec le compte test1. Dans le dossier document créer un dossier git et un sous dossier ”ssh python”.

git clone <https://git.univ-pau.fr/tlabachot/ssh-python.git>

2.2.2 / Créer le premier fichier

Créer une deuxième VM et installer ssh dessus.

Dans le dossier git de ssh-python créer le fichier ssh.py Voici le contenu du fichier ssh.py :

#!/ usr / bin / env python3

import paramiko
## Information de connexion
host = "IP"
username = "compte"
password = "motdepasse"

client = paramiko . client . SSHClient ()
client . set_missing_host_key_policy ( paramiko . AutoAddPolicy ())
client . connect (host , username = username , password = password )
_stdin , _stdout , _stderr = client . exec_command ("ip a")
print ( _stdout . read (). decode ())
client . close ()

A la place de IP mettre l’IP de la deuxième VM et mettre l’utilisateur à la place de compte et mettre le mot de passe a la place de motdepasse.

Tester le code avec la commande suivante

chmod u+x ssh.py
python3 ssh.py

Si le code fonctionne :

git add ssh.py
git commit -m v-0.1
git push <https://git.univ-pau.fr/tlabachot/ssh-python.git> master