e4ec487287
- agent2_deploy.py : bot XMPP avec machine à états pour le déploiement guidé - deployer.py : logique SSH partagée (paramiko) - deploy.py : script CLI standalone (après git clone) - agents_catalog.json : catalogue des agents déployables - README.md : documentation complète Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
150 lines
4.0 KiB
Markdown
150 lines
4.0 KiB
Markdown
# Agent2_Deploy — Agent de déploiement
|
|
|
|
Agent spécialisé dans le déploiement d'autres agents sur des machines distantes ou locales. Interactif via XMPP, il guide l'utilisateur étape par étape pour déployer un agent via SSH, puis notifie agent1 du nouveau déploiement.
|
|
|
|
## Rôle
|
|
|
|
- Déployer des agents spécialisés sur n'importe quelle machine via SSH
|
|
- Guider l'utilisateur interactivement (choix de l'agent, IP, credentials SSH, config XMPP/MQTT)
|
|
- Cloner automatiquement le dépôt git de l'agent cible
|
|
- Créer le service systemd sur la machine distante
|
|
- Notifier agent1 du nouveau déploiement (via MQTT)
|
|
|
|
## Agents déployables
|
|
|
|
Définis dans `agents_catalog.json` :
|
|
|
|
| Agent | Description |
|
|
|---|---|
|
|
| `agent2_debian13` | Spécialiste Debian (apt, systemd, docker...) |
|
|
| `agent2_ansible` | Automatisation Ansible (playbooks, ad-hoc...) |
|
|
| `agent2_deploy` | Agent de déploiement (ce même agent) |
|
|
|
|
## Utilisation via XMPP
|
|
|
|
Contacter `agent2_deploy@xmpp.ovh` via XMPP :
|
|
|
|
```
|
|
!deploy # Démarrer un déploiement guidé
|
|
!agents # Lister les agents disponibles
|
|
!annuler # Annuler le déploiement en cours
|
|
!help # Aide
|
|
```
|
|
|
|
### Déroulement du déploiement guidé
|
|
|
|
1. Choix de l'agent à déployer
|
|
2. Adresse IP de la machine cible
|
|
3. Nom d'utilisateur SSH
|
|
4. Authentification : mot de passe ou clé SSH
|
|
5. JID XMPP pour l'instance déployée
|
|
6. Mot de passe XMPP
|
|
7. Adresse du broker MQTT
|
|
8. Confirmation et déploiement
|
|
|
|
## Utilisation en mode CLI (depuis git clone)
|
|
|
|
Cloner ce dépôt sur n'importe quelle machine et lancer le script :
|
|
|
|
```bash
|
|
# Déploiement SSH vers une machine distante
|
|
git clone https://git.piaf.im/sylvain/agent2_deploy.git
|
|
cd agent2_deploy
|
|
python3 deploy.py
|
|
|
|
# Installation locale (sur la machine cible elle-même)
|
|
python3 deploy.py --local agent2_debian13
|
|
python3 deploy.py --local agent2_ansible
|
|
```
|
|
|
|
## Déploiement de agent2_deploy lui-même
|
|
|
|
### Prérequis sur la machine hôte
|
|
|
|
```bash
|
|
apt-get install -y python3 python3-venv python3-paramiko git mosquitto
|
|
```
|
|
|
|
### Installation manuelle
|
|
|
|
```bash
|
|
git clone https://git.piaf.im/sylvain/agent2_deploy.git /opt/agent2_deploy
|
|
cd /opt/agent2_deploy
|
|
|
|
# Configurer
|
|
nano config/config.json
|
|
|
|
# Service systemd
|
|
cat > /etc/systemd/system/agent2_deploy.service << 'EOF'
|
|
[Unit]
|
|
Description=Agent2 Deploy
|
|
After=network.target mosquitto.service agent.service
|
|
Wants=mosquitto.service
|
|
|
|
[Service]
|
|
Type=simple
|
|
WorkingDirectory=/opt/agent2_deploy
|
|
ExecStart=/usr/bin/python3 /opt/agent2_deploy/agent2_deploy.py
|
|
Restart=always
|
|
RestartSec=5
|
|
StandardOutput=journal
|
|
StandardError=journal
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
systemctl daemon-reload
|
|
systemctl enable agent2_deploy
|
|
systemctl start agent2_deploy
|
|
```
|
|
|
|
## Configuration (`config/config.json`)
|
|
|
|
```json
|
|
{
|
|
"xmpp_jid" : "agent2_deploy@xmpp.ovh",
|
|
"xmpp_pass" : "<mot_de_passe>",
|
|
"admin_jid" : "sylvain@xmpp.ovh",
|
|
"mqtt_host" : "localhost",
|
|
"mqtt_port" : 1883,
|
|
"mqtt_client_id": "agent2_deploy",
|
|
"mqtt_inbox" : "agents/agent2_deploy/inbox",
|
|
"mqtt_outbox" : "agents/agent1/inbox",
|
|
"agent1_inbox" : "agents/agent1/inbox"
|
|
}
|
|
```
|
|
|
|
## Prérequis sur les machines cibles
|
|
|
|
La machine sur laquelle déployer doit être accessible via SSH. Le script installe automatiquement :
|
|
- `python3`, `python3-pip`, `python3-venv`, `git`
|
|
- Les dépendances Python de l'agent (via pip dans le venv)
|
|
|
|
L'utilisateur SSH doit avoir les droits `sudo` ou être `root` (pour systemd et apt).
|
|
|
|
## Ajouter un nouvel agent au catalogue
|
|
|
|
Editer `agents_catalog.json` :
|
|
|
|
```json
|
|
{
|
|
"agent2_monagent": {
|
|
"description" : "Description de l'agent",
|
|
"repo_url" : "https://git.piaf.im/sylvain/agent2_monagent.git",
|
|
"install_path" : "/opt/agent2_monagent",
|
|
"service_name" : "agent2_monagent",
|
|
"main_script" : "agent2_monagent.py",
|
|
"mqtt_inbox" : "agents/agent2_monagent/inbox",
|
|
"mqtt_outbox" : "agents/agent1/inbox",
|
|
"dependencies" : ["slixmpp", "paho-mqtt", "requests"]
|
|
}
|
|
}
|
|
```
|
|
|
|
## Logs
|
|
|
|
```bash
|
|
journalctl -u agent2_deploy -f
|
|
```
|