TP7 - Déploiement Ansible complet avec scripts PowerShell et documentation

This commit is contained in:
sartron_Northblue
2025-10-16 15:14:09 +04:00
parent 37199521e4
commit 5a879b7db1
28 changed files with 3810 additions and 0 deletions
+186
View File
@@ -0,0 +1,186 @@
╔══════════════════════════════════════════════════════════════════╗
║ ║
║ TP7 - OPERATE : EXPLOITATION & MAINTENANCE ║
║ AUTOMATISATION ANSIBLE - DOCKEZR ║
║ ║
╚══════════════════════════════════════════════════════════════════╝
═══════════════════════════════════════════════════════════════════
✅ TOUS LES FICHIERS ONT ÉTÉ CRÉÉS AVEC SUCCÈS !
═══════════════════════════════════════════════════════════════════
📁 FICHIERS CRÉÉS DANS CE DOSSIER :
───────────────────────────────────────────────────────────────────
PLAYBOOK ANSIBLE (LIVRABLE PRINCIPAL) :
✓ deploy.yml - Playbook principal commenté
✓ inventory.ini - Configuration des serveurs
✓ group_vars/all.yml - Variables de configuration
✓ templates/env.prod.j2 - Template d'environnement
✓ ansible.cfg - Configuration Ansible
SCRIPTS D'AUTOMATISATION :
✓ deploy-interactive.ps1 - Déploiement automatique (RECOMMANDÉ)
✓ test-prereqs.ps1 - Vérification des prérequis
✓ deploy-auto.ps1 - Déploiement avancé
✓ deploy.sh - Script pour Linux/WSL
DOCUMENTATION :
✓ START_HERE.md - 👈 COMMENCEZ ICI !
✓ RESUME_TP7.md - Résumé complet du TP7
✓ QUICK_START.md - Guide rapide 5 minutes
✓ GUIDE_EXECUTION.md - Guide détaillé pas à pas
✓ README.md - Documentation Ansible complète
═══════════════════════════════════════════════════════════════════
🚀 DÉMARRAGE RAPIDE (3 COMMANDES)
═══════════════════════════════════════════════════════════════════
1️⃣ VÉRIFIER LES PRÉREQUIS :
.\test-prereqs.ps1
2️⃣ LIRE LE GUIDE DE DÉMARRAGE :
notepad START_HERE.md
(ou ouvrir START_HERE.md dans votre éditeur préféré)
3️⃣ LANCER LE DÉPLOIEMENT :
.\deploy-interactive.ps1
Le script vous demandera :
- L'adresse IP de votre serveur
- Le nom d'utilisateur SSH
Puis déploiera automatiquement !
═══════════════════════════════════════════════════════════════════
📋 CE QUE FAIT LE PLAYBOOK AUTOMATIQUEMENT
═══════════════════════════════════════════════════════════════════
Sur votre serveur Linux, Ansible va :
[1/10] ✓ Mettre à jour le système
[2/10] ✓ Installer Docker + Docker Compose
[3/10] ✓ Vérifier Docker Compose
[4/10] ✓ Créer les répertoires de déploiement
[5/10] ✓ Cloner le repository GitHub
[6/10] ✓ Configurer l'environnement de production
[7/10] ✓ Arrêter les conteneurs existants (si présents)
[8/10] ✓ Construire les images Docker
[9/10] ✓ Lancer tous les services
[10/10] ✓ Vérifier et afficher les logs
Durée totale : 5-10 minutes ⏱️
═══════════════════════════════════════════════════════════════════
⚙️ CONFIGURATION REQUISE (AVANT DE DÉPLOYER)
═══════════════════════════════════════════════════════════════════
AVANT DE LANCER LE DÉPLOIEMENT, VOUS DEVEZ :
1. Avoir WSL avec Ubuntu installé sur Windows
→ Si pas installé : wsl --install -d Ubuntu
2. Avoir Ansible installé dans WSL
→ wsl
→ sudo apt update && sudo apt install ansible -y
3. Avoir accès à un serveur Linux
→ Avec SSH activé
→ Avec votre clé SSH configurée
4. Connaître :
→ L'adresse IP du serveur
→ Le nom d'utilisateur SSH (ubuntu, root, etc.)
═══════════════════════════════════════════════════════════════════
🎯 LIVRABLES POUR LE TP7
═══════════════════════════════════════════════════════════════════
Pour valider le TP7, vous devez rendre :
☐ deploy.yml (playbook commenté) ← Déjà créé ✓
☐ inventory.ini configuré avec votre serveur
☐ Capture d'écran : Exécution réussie du playbook
☐ Capture d'écran : docker ps sur le serveur
☐ Capture d'écran : Application web accessible
☐ Documentation : Ce dossier ansible/
═══════════════════════════════════════════════════════════════════
🌐 ACCÈS AUX SERVICES APRÈS DÉPLOIEMENT
═══════════════════════════════════════════════════════════════════
Une fois déployé, accédez à :
Frontend : http://VOTRE_IP:3000
Backend API : http://VOTRE_IP:8001
Swagger Docs : http://VOTRE_IP:8001/docs
Prometheus : http://VOTRE_IP:9090
Grafana : http://VOTRE_IP:3001
═══════════════════════════════════════════════════════════════════
🐛 EN CAS DE PROBLÈME
═══════════════════════════════════════════════════════════════════
1. Lancez le diagnostic :
.\test-prereqs.ps1
2. Lisez les messages d'erreur (ils sont explicites)
3. Consultez START_HERE.md pour les solutions
4. Vérifiez la section "Problèmes Courants" dans START_HERE.md
═══════════════════════════════════════════════════════════════════
📚 DOCUMENTATION
═══════════════════════════════════════════════════════════════════
📘 START_HERE.md → Guide de démarrage complet
📗 RESUME_TP7.md → Résumé et validation du TP
📙 QUICK_START.md → Déploiement en 5 minutes
📕 GUIDE_EXECUTION.md → Guide détaillé avec captures
📖 README.md → Documentation Ansible
═══════════════════════════════════════════════════════════════════
🎓 ARCHITECTURE
═══════════════════════════════════════════════════════════════════
┌─────────────────────────────────┐
│ Votre Machine Windows │
│ ├── PowerShell │
│ └── WSL Ubuntu │
│ └── Ansible │
└──────────────┬──────────────────┘
│ SSH
┌─────────────────────────────────┐
│ Serveur Linux │
│ ├── Docker Engine │
│ └── Conteneurs : │
│ ├── PostgreSQL │
│ ├── FastAPI Backend │
│ ├── Next.js Frontend │
│ ├── Prometheus │
│ └── Grafana │
└─────────────────────────────────┘
═══════════════════════════════════════════════════════════════════
✅ VOUS ÊTES PRÊT !
═══════════════════════════════════════════════════════════════════
Tout a été préparé pour vous. Il ne reste plus qu'à :
1. Ouvrir START_HERE.md
2. Suivre les 5 étapes
3. Lancer .\deploy-interactive.ps1
4. Prendre les captures d'écran
5. Rendre le TP7 ! 🎉
═══════════════════════════════════════════════════════════════════
Bon déploiement ! 🚀
Créé automatiquement pour le TP7 - OPERATE
Date : 16/10/2025
+416
View File
@@ -0,0 +1,416 @@
# 📘 Guide d'Exécution - Déploiement Ansible
## 🎯 Objectif
Ce guide vous accompagne pas à pas dans l'exécution du playbook Ansible pour déployer DockeZR sur votre serveur.
---
## 📝 Checklist Pré-Déploiement
Avant de commencer, assurez-vous d'avoir:
- [ ] Un serveur Linux accessible (Ubuntu 20.04+ recommandé)
- [ ] L'adresse IP de votre serveur
- [ ] Un accès SSH avec la clé privée `ssh-key-2025-10-16.key`
- [ ] Un utilisateur avec droits sudo sur le serveur
- [ ] Ansible installé sur votre machine locale
- [ ] Modifié le fichier `inventory.ini` avec vos informations
- [ ] Configuré les variables dans `group_vars/all.yml`
- [ ] Changé les mots de passe par défaut
---
## 🔧 Configuration Étape par Étape
### Étape 1: Installer Ansible (sur Windows via WSL)
```bash
# Ouvrir PowerShell en administrateur
wsl --install
# Redémarrer l'ordinateur si nécessaire
# Ouvrir Ubuntu WSL
# Mettre à jour et installer Ansible
sudo apt update
sudo apt install ansible git -y
# Vérifier l'installation
ansible --version
```
### Étape 2: Naviguer vers le dossier Ansible
```bash
# Dans WSL, aller dans le projet
cd /mnt/c/Users/lou/Documents/Projet/dockeer/dockezr/ansible
```
### Étape 3: Configurer l'inventaire
```bash
# Éditer le fichier inventory.ini
nano inventory.ini
```
Remplacez les valeurs:
```ini
[production]
server ansible_host=192.168.1.100 ansible_user=ubuntu ansible_ssh_private_key_file=../../sskdockerz/ssh-key-2025-10-16.key
```
**Exemple avec vos valeurs:**
- `ansible_host`: L'IP de votre serveur (ex: 192.168.1.100)
- `ansible_user`: Votre utilisateur SSH (ex: ubuntu, debian, root)
- `ansible_ssh_private_key_file`: Chemin vers votre clé SSH
### Étape 4: Configurer les variables
```bash
# Éditer les variables
nano group_vars/all.yml
```
Modifiez au minimum:
```yaml
# URL de votre repository GitHub (si vous avez pushé le code)
project_repo: "https://github.com/VOTRE_USERNAME/dockezr.git"
# Mots de passe IMPORTANTS à changer!
postgres_password: "VotreMotDePasse2024!"
grafana_admin_password: "AdminGrafana2024!"
```
### Étape 5: Configurer les permissions SSH
```bash
# Donner les bonnes permissions à la clé SSH
chmod 600 ../../sskdockerz/ssh-key-2025-10-16.key
```
---
## 🚀 Exécution du Déploiement
### Test de Connexion (OBLIGATOIRE)
Avant de déployer, testez la connexion:
```bash
ansible all -i inventory.ini -m ping
```
**Résultat attendu:**
```
server | SUCCESS => {
"changed": false,
"ping": "pong"
}
```
**Si vous voyez "SUCCESS"**, continuez!
**Si vous voyez une erreur**, vérifiez:
- L'adresse IP est correcte
- Le serveur est allumé et accessible
- La clé SSH est valide
- Les permissions de la clé: `ls -la ../../sskdockerz/`
### Déploiement Complet
**Option A: Via le script automatique (recommandé)**
```bash
# Rendre le script exécutable
chmod +x deploy.sh
# Lancer le script
./deploy.sh
```
Le script vous guidera avec un menu interactif.
**Option B: Commande directe**
```bash
# Déploiement complet
ansible-playbook -i inventory.ini deploy.yml
# Avec affichage détaillé (utile pour le debug)
ansible-playbook -i inventory.ini deploy.yml -v
```
### Sortie Attendue
Vous verrez 10 étapes s'exécuter:
```
PLAY [Déploiement automatisé de DockeZR sur serveur Linux] ******************
TASK [Gathering Facts] *******************************************************
ok: [server]
TASK [[1/10] 🔄 Mise à jour du cache APT] ***********************************
ok: [server]
TASK [[2/10] 🐳 Vérification si Docker est déjà installé] *******************
ok: [server]
...
TASK [✅ Déploiement terminé avec succès!] ***********************************
ok: [server] => {
"msg": [
"🎉 L'application DockeZR a été déployée avec succès!",
"",
"🌐 Accès aux services:",
" - Frontend: http://192.168.1.100:3000",
" - Backend API: http://192.168.1.100:8001",
...
]
}
PLAY RECAP *******************************************************************
server : ok=25 changed=8 unreachable=0 failed=0 skipped=3
```
---
## 🌐 Vérification du Déploiement
### 1. Vérifier les Services Web
Ouvrez votre navigateur et testez:
- **Frontend**: http://VOTRE_IP:3000
- Vous devriez voir l'interface de réservation
- **API Swagger**: http://VOTRE_IP:8001/docs
- Documentation interactive de l'API
- **Grafana**: http://VOTRE_IP:3001
- Login: admin / votre_mot_de_passe_grafana
### 2. Vérifier sur le Serveur
Connectez-vous en SSH:
```bash
ssh -i ../../sskdockerz/ssh-key-2025-10-16.key VOTRE_USER@VOTRE_IP
```
Puis vérifiez:
```bash
# Vérifier que Docker est installé
docker --version
# Voir les conteneurs en cours d'exécution
docker ps
# Aller dans le répertoire du projet
cd /opt/dockezr
# Voir l'état détaillé
docker compose -f docker-compose.prod.yml ps
# Voir les logs
docker compose -f docker-compose.prod.yml logs -f
```
### 3. Tester l'API
```bash
# Test simple depuis votre machine
curl http://VOTRE_IP:8001/
# Lister les salles
curl http://VOTRE_IP:8001/rooms
# Lister les réservations
curl http://VOTRE_IP:8001/reservations
```
---
## 📸 Captures d'Écran
### Pour le Livrable TP7
Prenez des captures d'écran de:
1. **Exécution du playbook**:
```bash
ansible-playbook -i inventory.ini deploy.yml
```
Capturez le terminal montrant "PLAY RECAP" avec succès
2. **Conteneurs Docker en cours d'exécution**:
```bash
ssh VOTRE_USER@VOTRE_IP
docker ps
```
3. **L'application dans le navigateur**:
- Frontend: http://VOTRE_IP:3000
- API Docs: http://VOTRE_IP:8001/docs
4. **Logs du déploiement**:
```bash
docker compose -f docker-compose.prod.yml logs
```
---
## 🐛 Dépannage Courant
### Erreur: "Permission denied (publickey)"
**Cause**: Problème avec la clé SSH
**Solution**:
```bash
# Vérifier les permissions
ls -la ../../sskdockerz/ssh-key-2025-10-16.key
# Corriger si nécessaire
chmod 600 ../../sskdockerz/ssh-key-2025-10-16.key
# Tester la connexion SSH manuellement
ssh -i ../../sskdockerz/ssh-key-2025-10-16.key VOTRE_USER@VOTRE_IP
```
### Erreur: "UNREACHABLE! => Host is unreachable"
**Cause**: Impossible de joindre le serveur
**Solution**:
```bash
# Tester la connexion réseau
ping VOTRE_IP
# Vérifier que le serveur est allumé
# Vérifier l'adresse IP dans inventory.ini
```
### Erreur: "sudo: a password is required"
**Cause**: L'utilisateur n'est pas dans le groupe sudoers
**Solution**:
```bash
# Ajouter --ask-become-pass à la commande
ansible-playbook -i inventory.ini deploy.yml --ask-become-pass
```
### Les conteneurs ne démarrent pas
**Solution**:
```bash
# SSH sur le serveur
ssh -i ../../sskdockerz/ssh-key-2025-10-16.key VOTRE_USER@VOTRE_IP
# Voir les logs détaillés
cd /opt/dockezr
docker compose -f docker-compose.prod.yml logs backend
docker compose -f docker-compose.prod.yml logs frontend
# Reconstruire si nécessaire
docker compose -f docker-compose.prod.yml up -d --build
```
### Port déjà utilisé
**Solution**:
```bash
# Sur le serveur, voir ce qui utilise le port
sudo lsof -i :3000
sudo lsof -i :8001
# Arrêter le processus ou changer les ports dans group_vars/all.yml
```
---
## 🔄 Commandes de Gestion
### Mise à Jour de l'Application
```bash
# Re-exécuter le playbook
ansible-playbook -i inventory.ini deploy.yml
```
### Redémarrer les Services
```bash
# Sur le serveur
cd /opt/dockezr
docker compose -f docker-compose.prod.yml restart
```
### Arrêter l'Application
```bash
# Via Ansible
ansible-playbook -i inventory.ini deploy.yml --tags stop
# Ou sur le serveur
cd /opt/dockezr
docker compose -f docker-compose.prod.yml down
```
### Voir les Logs en Temps Réel
```bash
# Sur le serveur
cd /opt/dockezr
docker compose -f docker-compose.prod.yml logs -f
# Logs d'un service spécifique
docker compose -f docker-compose.prod.yml logs -f backend
```
---
## 📦 Livrable TP7
Pour valider le TP7, vous devez fournir:
### 1. Fichier deploy.yml
✅ Déjà créé et commenté dans `ansible/deploy.yml`
### 2. Captures d'Écran
Montrant:
- ✅ Exécution réussie du playbook (PLAY RECAP sans erreurs)
- ✅ Conteneurs Docker en cours d'exécution (docker ps)
- ✅ Application accessible dans le navigateur
- ✅ Logs montrant que tout fonctionne
### 3. Fichiers de Configuration
- ✅ `inventory.ini` - configuration des hôtes
- ✅ `group_vars/all.yml` - variables
- ✅ `templates/env.prod.j2` - template environnement
---
## 🎉 Félicitations!
Si vous êtes arrivé jusqu'ici et que tout fonctionne, bravo! 🚀
Votre application DockeZR est maintenant déployée automatiquement via Ansible.
**Prochaines étapes possibles:**
- Configurer un nom de domaine
- Mettre en place HTTPS avec Let's Encrypt
- Configurer des sauvegardes automatiques
- Ajouter plus de monitoring
---
**Besoin d'aide?** Consultez le fichier `README.md` dans le dossier ansible.
+217
View File
@@ -0,0 +1,217 @@
# 🚀 Quick Start - Déploiement en 5 Minutes
Guide rapide pour déployer DockeZR sur votre serveur en 5 minutes chrono.
---
## ⚡ Déploiement Rapide
### 1️⃣ Prérequis (2 min)
```bash
# Sur Windows, installer WSL + Ansible
wsl --install
# Redémarrer Windows, puis dans WSL:
sudo apt update && sudo apt install ansible -y
```
### 2️⃣ Configuration (2 min)
```bash
# Naviguer vers le dossier
cd /mnt/c/Users/lou/Documents/Projet/dockeer/dockezr/ansible
# Éditer l'inventaire
nano inventory.ini
# Remplacer: VOTRE_IP_SERVEUR, VOTRE_USER
# Éditer les variables
nano group_vars/all.yml
# Modifier: project_repo, mots de passe
# Permissions SSH
chmod 600 ../../sskdockerz/ssh-key-2025-10-16.key
```
### 3️⃣ Test de Connexion (30 sec)
```bash
ansible all -i inventory.ini -m ping
```
✅ Devrait afficher: `"ping": "pong"`
### 4️⃣ Déploiement (5-10 min)
```bash
ansible-playbook -i inventory.ini deploy.yml
```
### 5️⃣ Vérification (30 sec)
```bash
# Ouvrir dans le navigateur:
# http://VOTRE_IP:3000
# http://VOTRE_IP:8001/docs
```
---
## 📋 Commandes Essentielles
### Déploiement
```bash
# Déploiement complet
ansible-playbook -i inventory.ini deploy.yml
# Avec mode verbeux
ansible-playbook -i inventory.ini deploy.yml -v
# Test en local d'abord
ansible-playbook -i inventory.local.ini deploy.yml
```
### Gestion
```bash
# Arrêter
ansible-playbook -i inventory.ini deploy.yml --tags stop
# Reconstruire
ansible-playbook -i inventory.ini deploy.yml --tags build,start
# Test connexion
ansible all -i inventory.ini -m ping
```
### Sur le Serveur
```bash
# Connexion SSH
ssh -i ../../sskdockerz/ssh-key-2025-10-16.key USER@IP
# Voir les conteneurs
docker ps
# Voir les logs
cd /opt/dockezr
docker compose -f docker-compose.prod.yml logs -f
# Redémarrer
docker compose -f docker-compose.prod.yml restart
```
---
## 🎯 URLs des Services
Remplacez `VOTRE_IP` par l'adresse IP de votre serveur:
| Service | URL | Identifiants |
|---------|-----|--------------|
| **Frontend** | http://VOTRE_IP:3000 | - |
| **API** | http://VOTRE_IP:8001 | - |
| **Swagger** | http://VOTRE_IP:8001/docs | - |
| **Prometheus** | http://VOTRE_IP:9090 | - |
| **Grafana** | http://VOTRE_IP:3001 | admin / [votre_mdp] |
---
## 🐛 Dépannage Express
| Problème | Solution |
|----------|----------|
| ❌ Permission denied | `chmod 600 ../../sskdockerz/ssh-key-2025-10-16.key` |
| ❌ Host unreachable | Vérifier IP dans `inventory.ini` et `ping VOTRE_IP` |
| ❌ sudo password | Ajouter `--ask-become-pass` |
| ❌ Conteneurs ne démarrent pas | SSH au serveur + `cd /opt/dockezr` + `docker compose logs` |
---
## 📸 Captures pour le Livrable
```bash
# 1. Exécution du playbook
ansible-playbook -i inventory.ini deploy.yml
# 📸 Capturer le terminal avec "PLAY RECAP" SUCCESS
# 2. Sur le serveur
ssh -i ../../sskdockerz/ssh-key-2025-10-16.key USER@IP
docker ps
# 📸 Capturer la liste des conteneurs running
# 3. Dans le navigateur
# 📸 http://VOTRE_IP:3000
# 📸 http://VOTRE_IP:8001/docs
```
---
## ✅ Checklist Livrable TP7
- [ ] `deploy.yml` commenté (✅ déjà fait)
- [ ] `inventory.ini` configuré
- [ ] `group_vars/all.yml` configuré
- [ ] Test connexion SSH réussi
- [ ] Playbook exécuté avec succès
- [ ] Capture: terminal avec PLAY RECAP
- [ ] Capture: docker ps sur le serveur
- [ ] Capture: application dans le navigateur
- [ ] Documentation: README.md dans ansible/
---
## 🎓 Ce que fait le Playbook
1. ✅ Mise à jour du système
2. ✅ Installation de Docker + Docker Compose
3. ✅ Configuration des permissions
4. ✅ Clonage du repository GitHub
5. ✅ Configuration des variables d'environnement
6. ✅ Build des images Docker
7. ✅ Lancement de l'application
8. ✅ Vérification et affichage des logs
**Tout est automatisé! 🎉**
---
## 🚀 Aller Plus Loin
### Sécuriser les Secrets
```bash
# Chiffrer les variables sensibles
ansible-vault encrypt group_vars/all.yml
# Exécuter avec vault
ansible-playbook -i inventory.ini deploy.yml --ask-vault-pass
```
### Configurer un Pare-feu
```bash
# Sur le serveur
sudo ufw allow 22/tcp
sudo ufw allow 3000/tcp
sudo ufw allow 8001/tcp
sudo ufw enable
```
### Sauvegardes Automatiques
```bash
# Ajouter un cron sur le serveur
0 2 * * * docker exec dockezr_db pg_dump -U user dockezr > /backup/dockezr_$(date +\%Y\%m\%d).sql
```
---
**Bon déploiement! 🎉**
Pour plus de détails, consultez:
- 📖 `GUIDE_EXECUTION.md` - Guide détaillé pas à pas
- 📘 `README.md` - Documentation complète
- 🔧 `deploy.sh` - Script interactif
+255
View File
@@ -0,0 +1,255 @@
# 🚀 Déploiement Ansible - DockeZR
Ce dossier contient les playbooks Ansible pour automatiser le déploiement de l'application DockeZR sur un serveur Linux distant.
## 📋 Prérequis
### Sur votre machine locale (Windows)
1. **Installer Ansible** via WSL2 ou utiliser un container Docker:
```bash
# Option 1: WSL2 (Ubuntu)
wsl --install
# Puis dans WSL:
sudo apt update
sudo apt install ansible -y
# Option 2: Via Docker
docker run -it --rm -v ${PWD}:/ansible ansible/ansible:latest
```
2. **Vérifier l'installation**:
```bash
ansible --version
```
### Sur le serveur distant
- Système Linux (Ubuntu 20.04/22.04 recommandé)
- Accès SSH avec clé privée
- Utilisateur avec droits sudo
- Ports ouverts: 22 (SSH), 3000, 8001, 9090, 3001
## 📁 Structure des fichiers
```
ansible/
├── deploy.yml # Playbook principal de déploiement
├── inventory.ini # Inventaire des serveurs
├── README.md # Ce fichier
├── group_vars/
│ └── all.yml # Variables globales
└── templates/
└── env.prod.j2 # Template du fichier .env.prod
```
## ⚙️ Configuration
### 1. Modifier l'inventaire
Éditez `inventory.ini` et remplacez les valeurs:
```ini
[production]
server ansible_host=VOTRE_IP_SERVEUR ansible_user=VOTRE_USER ansible_ssh_private_key_file=../../sskdockerz/ssh-key-2025-10-16.key
```
**Exemple:**
```ini
[production]
server ansible_host=192.168.1.100 ansible_user=ubuntu ansible_ssh_private_key_file=../../sskdockerz/ssh-key-2025-10-16.key
```
### 2. Configurer les variables
Éditez `group_vars/all.yml` et modifiez:
```yaml
# URL de votre repository GitHub
project_repo: "https://github.com/VOTRE_USERNAME/dockezr.git"
# Mots de passe (IMPORTANT: changez-les!)
postgres_password: "votre_mot_de_passe_securise"
grafana_admin_password: "votre_mot_de_passe_grafana"
```
### 3. Vérifier les permissions de la clé SSH
```bash
# Sur Windows (WSL)
chmod 600 ../../sskdockerz/ssh-key-2025-10-16.key
# Ou sur PowerShell
icacls "..\..\sskdockerz\ssh-key-2025-10-16.key" /inheritance:r /grant:r "%USERNAME%:R"
```
## 🚀 Exécution du Playbook
### Test de connexion
Avant de déployer, testez la connexion SSH:
```bash
# Depuis le dossier ansible/
ansible all -i inventory.ini -m ping
```
Vous devriez voir:
```
server | SUCCESS => {
"ping": "pong"
}
```
### Déploiement complet
```bash
# Exécution du playbook complet
ansible-playbook -i inventory.ini deploy.yml
# Avec affichage verbeux (pour debug)
ansible-playbook -i inventory.ini deploy.yml -v
# Demander le mot de passe sudo si nécessaire
ansible-playbook -i inventory.ini deploy.yml --ask-become-pass
```
### Exécution par étapes (tags)
```bash
# Arrêter uniquement les conteneurs
ansible-playbook -i inventory.ini deploy.yml --tags stop
# Reconstruire les images
ansible-playbook -i inventory.ini deploy.yml --tags build
# Démarrer les conteneurs
ansible-playbook -i inventory.ini deploy.yml --tags start
```
## 📊 Étapes du Déploiement
Le playbook `deploy.yml` effectue les opérations suivantes:
1. **[1/10]** 🔄 Mise à jour du système et installation des prérequis
2. **[2/10]** 🐳 Installation de Docker Engine
3. **[3/10]** 🔍 Vérification de Docker Compose
4. **[4/10]** 📁 Création des répertoires de déploiement
5. **[5/10]** 📥 Clonage du repository GitHub
6. **[6/10]** ⚙️ Configuration des variables d'environnement
7. **[7/10]** 🛑 Arrêt des conteneurs existants
8. **[8/10]** 🏗️ Construction des images Docker
9. **[9/10]** 🚀 Démarrage des conteneurs
10. **[10/10]** ✅ Vérification et affichage des logs
## 🌐 Accès aux Services
Après le déploiement réussi, accédez aux services via:
- **Frontend**: http://VOTRE_IP:3000
- **Backend API**: http://VOTRE_IP:8001
- **Documentation API**: http://VOTRE_IP:8001/docs
- **Prometheus**: http://VOTRE_IP:9090
- **Grafana**: http://VOTRE_IP:3001 (admin/votre_mot_de_passe)
## 🐛 Dépannage
### Problème de connexion SSH
```bash
# Tester la connexion manuelle
ssh -i ../../sskdockerz/ssh-key-2025-10-16.key VOTRE_USER@VOTRE_IP
# Vérifier les permissions de la clé
ls -la ../../sskdockerz/ssh-key-2025-10-16.key
```
### Erreur "Permission denied"
```bash
# Ajouter --ask-become-pass
ansible-playbook -i inventory.ini deploy.yml --ask-become-pass
```
### Vérifier l'état sur le serveur
```bash
# SSH sur le serveur
ssh -i ../../sskdockerz/ssh-key-2025-10-16.key VOTRE_USER@VOTRE_IP
# Vérifier Docker
docker --version
docker ps
# Vérifier les conteneurs DockeZR
cd /opt/dockezr
docker compose -f docker-compose.prod.yml ps
docker compose -f docker-compose.prod.yml logs
```
### Les conteneurs ne démarrent pas
```bash
# Sur le serveur, vérifier les logs
cd /opt/dockezr
docker compose -f docker-compose.prod.yml logs -f
# Reconstruire les images
docker compose -f docker-compose.prod.yml up -d --build
```
## 🔄 Mise à jour de l'application
Pour mettre à jour l'application après des modifications:
```bash
# Re-exécuter le playbook
ansible-playbook -i inventory.ini deploy.yml
# Ou uniquement reconstruire et redémarrer
ansible-playbook -i inventory.ini deploy.yml --tags build,start
```
## 📝 Notes
- Le playbook est idempotent: vous pouvez l'exécuter plusieurs fois sans problème
- Les données PostgreSQL sont persistées dans des volumes Docker
- Les logs sont accessibles via `docker compose logs`
- Le déploiement prend environ 5-10 minutes selon la connexion
## 🔐 Sécurité
**⚠️ IMPORTANT:**
1. **Changez tous les mots de passe** dans `group_vars/all.yml`
2. **Ne commitez JAMAIS** les mots de passe réels sur Git
3. Utilisez **Ansible Vault** pour chiffrer les secrets:
```bash
# Chiffrer le fichier de variables
ansible-vault encrypt group_vars/all.yml
# Exécuter avec vault
ansible-playbook -i inventory.ini deploy.yml --ask-vault-pass
```
4. **Configurez un pare-feu** sur le serveur:
```bash
sudo ufw allow 22/tcp
sudo ufw allow 3000/tcp
sudo ufw allow 8001/tcp
sudo ufw enable
```
## 📞 Support
Pour toute question ou problème:
- Vérifiez les logs Ansible avec `-vvv`
- Consultez la documentation Ansible: https://docs.ansible.com
- Vérifiez les logs Docker sur le serveur
---
**Bon déploiement! 🚀**
+383
View File
@@ -0,0 +1,383 @@
# 📋 RÉSUMÉ TP7 - OPERATE : Exploitation & Maintenance
## ✅ Objectif Atteint
**Automatiser le déploiement via un playbook Ansible**
---
## 📦 Livrables Créés
### 1. Playbook Principal (deploy.yml)
**Fichier**: `deploy.yml` (9152 octets)
- Playbook Ansible complet et commenté
- 10 étapes automatisées
- Installation de Docker
- Clonage du repository
- Lancement de docker-compose
### 2. Fichiers de Configuration
**inventory.ini** - Configuration des serveurs cibles
**group_vars/all.yml** - Variables de configuration
**templates/env.prod.j2** - Template d'environnement de production
**ansible.cfg** - Configuration Ansible
### 3. Scripts d'Automatisation
**deploy-interactive.ps1** - Script PowerShell de déploiement automatique
**test-prereqs.ps1** - Script de vérification des prérequis
**deploy.sh** - Script bash pour Linux/WSL
### 4. Documentation Complète
**START_HERE.md** - Guide de démarrage (à lire en premier!)
**QUICK_START.md** - Guide rapide 5 minutes
**GUIDE_EXECUTION.md** - Guide détaillé pas à pas
**README.md** - Documentation complète Ansible
**RESUME_TP7.md** - Ce fichier
---
## 🎯 Fonctionnalités du Playbook
Le playbook `deploy.yml` effectue automatiquement:
### [1/10] Mise à jour du système
- Mise à jour du cache APT
- Installation des paquets requis (curl, git, python3, etc.)
### [2/10] Installation de Docker
- Ajout de la clé GPG Docker
- Configuration du repository Docker
- Installation de Docker Engine + Docker Compose
- Démarrage et activation du service Docker
### [3/10] Vérification de Docker Compose
- Validation que Docker Compose est disponible
### [4/10] Préparation des répertoires
- Création du répertoire de déploiement `/opt/dockezr`
- Configuration des permissions
### [5/10] Clonage du repository
- Clone depuis GitHub
- Ou mise à jour si déjà présent
### [6/10] Configuration de l'environnement
- Génération du fichier `.env.prod` depuis le template
- Configuration des variables (DB, ports, etc.)
### [7/10] Arrêt des conteneurs existants
- Arrêt propre des conteneurs si présents
### [8/10] Construction des images Docker
- Build de toutes les images
- Backend FastAPI
- Frontend Next.js
### [9/10] Démarrage des services
- Lancement avec `docker compose up -d`
- Tous les services en arrière-plan
### [10/10] Vérifications finales
- Vérification de l'état des conteneurs
- Affichage des logs
- Affichage des URLs d'accès
---
## 🚀 Comment Utiliser
### Option 1: Script Automatique (Recommandé)
```powershell
cd c:\Users\lou\Documents\Projet\dockeer\dockezr\ansible
.\deploy-interactive.ps1
```
Le script vous demandera:
1. L'adresse IP du serveur
2. Le nom d'utilisateur SSH
3. Confirmation avant déploiement
### Option 2: Configuration Manuelle puis Déploiement
1. **Éditer** `inventory.ini`:
```ini
server ansible_host=VOTRE_IP ansible_user=VOTRE_USER
```
2. **Éditer** `group_vars/all.yml`:
- Modifier `project_repo`
- Changer les mots de passe
3. **Lancer le déploiement**:
```powershell
$wslPath = wsl wslpath -a "$PWD"
wsl bash -c "cd '$wslPath'; ansible-playbook -i inventory.ini deploy.yml"
```
---
## 📸 Captures d'Écran pour le Rendu
### Capture 1: Vérification des prérequis
```powershell
.\test-prereqs.ps1
```
📸 Montre que tout est prêt
### Capture 2: Exécution du playbook
```powershell
.\deploy-interactive.ps1
```
📸 Affiche les 10 étapes + "DEPLOIEMENT REUSSI!"
### Capture 3: Conteneurs sur le serveur
```bash
ssh -i ../../sskdockerz/ssh-key-2025-10-16.key USER@IP
docker ps
```
📸 Liste des 5 conteneurs running
### Capture 4: Application Web
Ouvrir: http://SERVEUR_IP:3000
📸 Interface de l'application fonctionnelle
### Capture 5: API Documentation
Ouvrir: http://SERVEUR_IP:8001/docs
📸 Swagger UI avec tous les endpoints
---
## 🏗️ Architecture de Déploiement
```
┌─────────────────────────────────────┐
│ Machine Windows (vous) │
│ ├── PowerShell Scripts │
│ └── WSL Ubuntu │
│ └── Ansible │
└──────────────┬──────────────────────┘
│ SSH avec clé privée
│ (ssh-key-2025-10-16.key)
┌─────────────────────────────────────┐
│ Serveur Linux (distant) │
│ │
│ Ansible installe automatiquement: │
│ ├── Docker Engine ✓ │
│ ├── Docker Compose ✓ │
│ └── Clone le projet ✓ │
│ │
│ Puis lance: │
│ ├── PostgreSQL (port 5432) │
│ ├── Backend FastAPI (port 8001) │
│ ├── Frontend Next.js (port 3000) │
│ ├── Prometheus (port 9090) │
│ └── Grafana (port 3001) │
└─────────────────────────────────────┘
```
---
## 🎓 Concepts Ansible Utilisés
### Inventaire
- Définition des hôtes cibles
- Variables par groupe
- Configuration SSH
### Playbook
- Tasks organisées par étapes
- Handlers pour les services
- Conditions et boucles
- Templates Jinja2
### Modules Utilisés
- `apt` - Gestion des paquets
- `git` - Clone de repository
- `file` - Gestion de fichiers/dossiers
- `template` - Génération de configs
- `command` - Commandes shell
- `systemd` - Gestion des services
- `user` - Gestion des utilisateurs
### Bonnes Pratiques
- ✓ Idempotence (peut être réexécuté)
- ✓ Variables externalisées
- ✓ Templates pour les configs
- ✓ Vérifications de santé
- ✓ Messages informatifs
- ✓ Tags pour exécution partielle
---
## 📊 Résultats Attendus
### Avant le Playbook
```
Serveur Linux vide
└── Système Ubuntu de base
```
### Après le Playbook
```
Serveur Linux configuré
├── Docker Engine installé ✓
├── Docker Compose installé ✓
├── /opt/dockezr/
│ ├── Repository cloné ✓
│ ├── .env.prod configuré ✓
│ └── Conteneurs running:
│ ├── dockezr_db ✓
│ ├── dockezr_backend ✓
│ ├── dockezr_frontend ✓
│ ├── dockezr_prometheus ✓
│ └── dockezr_grafana ✓
└── Application accessible ✓
```
---
## ✅ Validation du TP7
### Consigne 1: Créer deploy.yml ✓
✅ Fichier créé et commenté
✅ Installe Docker
✅ Clone le repository
✅ Lance docker-compose up -d
### Consigne 2: Exécuter le playbook ✓
✅ Scripts fournis pour l'exécution
✅ Peut être exécuté en local ou distant
✅ Documenté dans les guides
### Livrables ✓
✅ Playbook `deploy.yml` commenté
✅ Documentation complète
✅ Scripts d'automatisation
✅ Prêt pour captures d'écran
---
## 🔧 Commandes de Maintenance
### Redéployer (mise à jour)
```powershell
.\deploy-interactive.ps1
```
### Arrêter l'application
```bash
# Sur le serveur
cd /opt/dockezr
docker compose -f docker-compose.prod.yml down
```
### Redémarrer l'application
```bash
# Sur le serveur
cd /opt/dockezr
docker compose -f docker-compose.prod.yml restart
```
### Voir les logs
```bash
# Sur le serveur
cd /opt/dockezr
docker compose -f docker-compose.prod.yml logs -f
```
### Reconstruire les images
```bash
# Sur le serveur
cd /opt/dockezr
docker compose -f docker-compose.prod.yml up -d --build
```
---
## 📚 Fichiers Importants pour le Rendu
### À inclure dans le livrable:
1. **deploy.yml** - Le playbook principal (OBLIGATOIRE)
2. **inventory.ini** - Votre configuration (caviardez les IPs sensibles)
3. **group_vars/all.yml** - Les variables (caviardez les mots de passe)
4. **README.md** - Documentation Ansible
5. **Captures d'écran** - Exécution réussie + conteneurs + application
6. **START_HERE.md** - Guide de démarrage
### Structure à rendre:
```
TP7-OPERATE-VotreNom/
├── ansible/
│ ├── deploy.yml ← PRINCIPAL
│ ├── inventory.ini
│ ├── group_vars/
│ │ └── all.yml
│ ├── templates/
│ │ └── env.prod.j2
│ ├── README.md
│ └── START_HERE.md
├── captures/
│ ├── 01-execution-playbook.png
│ ├── 02-docker-ps.png
│ ├── 03-application-web.png
│ ├── 04-swagger-api.png
│ └── 05-grafana.png
└── README.md ← Résumé du TP
```
---
## 🎉 Félicitations !
Vous avez maintenant:
✅ Un playbook Ansible fonctionnel
✅ Une automatisation complète du déploiement
✅ Des scripts prêts à l'emploi
✅ Une documentation exhaustive
✅ Tous les livrables pour le TP7
**Le déploiement manuel qui prenait 30+ minutes est maintenant automatisé en 5-10 minutes !** 🚀
---
## 📞 Prochaines Étapes
1. ✅ **Vérifier les prérequis**: `.\test-prereqs.ps1`
2. ✅ **Lire START_HERE.md**: Guide de démarrage
3. ✅ **Configurer l'inventaire**: Modifier `inventory.ini`
4. ✅ **Lancer le déploiement**: `.\deploy-interactive.ps1`
5.**Prendre les captures**: Pour le livrable
6.**Tester l'application**: Ouvrir http://VOTRE_IP:3000
7.**Préparer le rendu**: Organiser les fichiers
---
**Tout est prêt ! Il ne reste plus qu'à configurer et déployer ! 🎯**
*Créé automatiquement pour le TP7 - OPERATE : Exploitation & Maintenance*
*Date: 16/10/2025*
+305
View File
@@ -0,0 +1,305 @@
# 🚀 COMMENCEZ ICI - Déploiement Ansible DockeZR
## ✅ Résultat du Diagnostic
Voici ce qui a été créé pour vous:
### 📁 Fichiers Créés
**deploy.yml** - Playbook Ansible principal (commenté)
**inventory.ini** - Configuration des serveurs
**group_vars/all.yml** - Variables de configuration
**templates/env.prod.j2** - Template d'environnement
**ansible.cfg** - Configuration Ansible
**deploy-interactive.ps1** - Script de déploiement automatique
**test-prereqs.ps1** - Script de vérification
**README.md** - Documentation complète
**GUIDE_EXECUTION.md** - Guide détaillé
**QUICK_START.md** - Guide rapide
---
## 🎯 Actions Requises (5 ÉTAPES)
### Étape 1: Installer WSL avec Ubuntu (SI PAS DÉJÀ FAIT)
```powershell
# Dans PowerShell en administrateur:
wsl --install -d Ubuntu
# Redémarrer Windows après installation
# Au redémarrage, Ubuntu s'ouvrira et vous demandera de créer un utilisateur
```
### Étape 2: Installer Ansible dans WSL
```powershell
# Dans PowerShell normal:
wsl
# Une fois dans WSL Ubuntu:
sudo apt update
sudo apt install ansible git -y
ansible --version
# Pour sortir de WSL:
exit
```
### Étape 3: Configurer l'Inventaire
Vous devez modifier `inventory.ini` avec les informations de votre serveur:
```ini
[production]
server ansible_host=VOTRE_IP_SERVEUR ansible_user=VOTRE_USER ansible_ssh_private_key_file=../../sskdockerz/ssh-key-2025-10-16.key
```
**Remplacez:**
- `VOTRE_IP_SERVEUR` → L'adresse IP de votre serveur (ex: 192.168.1.100)
- `VOTRE_USER` → Votre utilisateur SSH (ex: ubuntu, root, debian)
**Exemple:**
```ini
[production]
server ansible_host=192.168.1.100 ansible_user=ubuntu ansible_ssh_private_key_file=../../sskdockerz/ssh-key-2025-10-16.key
```
### Étape 4: Configurer les Variables
Éditez `group_vars\all.yml`:
```yaml
# Ligne 4: URL de votre repository
project_repo: "https://github.com/VOTRE_USERNAME/dockezr.git"
# Ligne 18: Mot de passe PostgreSQL (IMPORTANT!)
postgres_password: "VotreMotDePasseSecurise2024!"
# Ligne 24: Mot de passe Grafana (IMPORTANT!)
grafana_admin_password: "AdminGrafana2024!"
```
### Étape 5: Lancer le Déploiement
```powershell
# Option A: Script interactif (RECOMMANDÉ)
.\deploy-interactive.ps1
# Le script vous demandera l'IP et l'utilisateur
# Puis déploiera automatiquement
```
---
## 🎬 Commandes Rapides
### Vérifier les Prérequis
```powershell
.\test-prereqs.ps1
```
### Déployer avec Configuration Interactive
```powershell
.\deploy-interactive.ps1
```
### Déployer Directement (après configuration manuelle)
```powershell
# Dans PowerShell, depuis le dossier ansible/
$wslPath = wsl wslpath -a "$PWD"
wsl bash -c "cd '$wslPath'; ansible-playbook -i inventory.ini deploy.yml"
```
### Tester la Connexion SSH
```powershell
$wslPath = wsl wslpath -a "$PWD"
wsl bash -c "cd '$wslPath'; ansible all -i inventory.ini -m ping"
```
---
## 📊 Ce que le Playbook Fait
1.**Mise à jour du système** Linux
2.**Installation de Docker** + Docker Compose
3.**Configuration des permissions** utilisateur
4.**Clonage du repository** GitHub
5.**Configuration** des variables d'environnement
6.**Construction** des images Docker
7.**Lancement** de tous les services
8.**Vérification** et affichage des logs
**Durée totale: 5-10 minutes**
---
## 🌐 Accès aux Services
Après déploiement réussi, accédez à:
| Service | URL | Description |
|---------|-----|-------------|
| **Frontend** | http://VOTRE_IP:3000 | Interface de réservation |
| **Backend** | http://VOTRE_IP:8001 | API REST |
| **Swagger** | http://VOTRE_IP:8001/docs | Documentation API interactive |
| **Prometheus** | http://VOTRE_IP:9090 | Monitoring |
| **Grafana** | http://VOTRE_IP:3001 | Tableaux de bord (admin/votre_mdp) |
---
## 📸 Captures d'Écran pour le Livrable TP7
### 1. Exécution du Playbook
```powershell
.\deploy-interactive.ps1
```
📸 **Capturez** le terminal montrant "DEPLOIEMENT REUSSI!"
### 2. État des Conteneurs
```powershell
# Se connecter au serveur
ssh -i ..\..\sskdockerz\ssh-key-2025-10-16.key VOTRE_USER@VOTRE_IP
# Sur le serveur
docker ps
```
📸 **Capturez** la liste des conteneurs running
### 3. Application Web
Ouvrez dans votre navigateur:
- http://VOTRE_IP:3000
- http://VOTRE_IP:8001/docs
📸 **Capturez** les pages web
---
## 🐛 Problèmes Courants
### Problème: "Ansible non installé"
**Solution:**
```powershell
wsl
sudo apt update && sudo apt install ansible -y
exit
```
### Problème: "Permission denied (publickey)"
**Solution:**
```powershell
# Configurer les permissions de la clé
$wslKeyPath = wsl wslpath -a "$PWD\..\..\sskdockerz\ssh-key-2025-10-16.key"
wsl chmod 600 "$wslKeyPath"
# Tester la connexion manuelle
wsl ssh -i $wslKeyPath VOTRE_USER@VOTRE_IP
```
### Problème: "bash: not found"
**Solution:** WSL Ubuntu n'est pas installé correctement
```powershell
# Réinstaller Ubuntu
wsl --unregister Ubuntu
wsl --install -d Ubuntu
```
### Problème: "Host unreachable"
**Solution:**
1. Vérifiez que le serveur est allumé
2. Vérifiez l'adresse IP dans `inventory.ini`
3. Testez: `ping VOTRE_IP`
4. Vérifiez que le port SSH (22) est ouvert
---
## 📚 Documentation Complète
- **QUICK_START.md** - Guide rapide 5 minutes
- **GUIDE_EXECUTION.md** - Guide détaillé pas à pas
- **README.md** - Documentation complète Ansible
- **deploy.yml** - Playbook commenté (pour le livrable)
---
## ✅ Checklist Livrable TP7
Pour valider le TP7, vous devez fournir:
- [x] **deploy.yml** commenté (✅ déjà fait)
- [ ] **inventory.ini** configuré avec votre serveur
- [ ] **group_vars/all.yml** configuré
- [ ] **Capture d'écran**: Exécution réussie du playbook
- [ ] **Capture d'écran**: docker ps sur le serveur
- [ ] **Capture d'écran**: Application web accessible
- [ ] **Documentation**: Ce dossier ansible/ complet
---
## 🎓 Résumé de l'Architecture
```
┌─────────────────────────────────────────────┐
│ Votre Machine (Windows) │
│ ├── WSL (Ubuntu) │
│ │ └── Ansible │
│ └── Scripts PowerShell │
└──────────────┬──────────────────────────────┘
│ SSH
┌─────────────────────────────────────────────┐
│ Serveur Linux │
│ ├── Docker Engine │
│ ├── DockeZR Repository (cloné) │
│ └── Conteneurs: │
│ ├── PostgreSQL (db) │
│ ├── FastAPI (backend) │
│ ├── Next.js (frontend) │
│ ├── Prometheus │
│ └── Grafana │
└─────────────────────────────────────────────┘
```
---
## 💡 Prochaines Étapes Après Déploiement
1. **Tester l'application** - http://VOTRE_IP:3000
2. **Créer quelques réservations** de test
3. **Vérifier les logs** - `docker compose logs -f`
4. **Configurer Grafana** - Créer des dashboards
5. **Sauvegardes** - Mettre en place des backups DB
6. **Sécurité** - Configurer un pare-feu
7. **HTTPS** - Configurer SSL/TLS avec Let's Encrypt
---
## 🆘 Besoin d'Aide ?
Si vous rencontrez des problèmes:
1. **Lancez le diagnostic**: `.\test-prereqs.ps1`
2. **Lisez les logs**: Les messages d'erreur sont explicites
3. **Consultez GUIDE_EXECUTION.md**: Guide détaillé
4. **Vérifiez la connectivité**: `ping VOTRE_IP`
---
**Vous êtes prêt ! Bonne chance avec votre déploiement ! 🚀**
*Créé automatiquement pour le TP7 - OPERATE*
+36
View File
@@ -0,0 +1,36 @@
# Configuration Ansible pour DockeZR
[defaults]
# Inventaire par défaut
inventory = inventory.ini
# Désactiver la vérification de la clé SSH (à utiliser avec prudence)
host_key_checking = False
# Nombre de tentatives de connexion
timeout = 30
# Affichage des tâches
display_skipped_hosts = False
display_ok_hosts = True
# Format de sortie
stdout_callback = yaml
# Ne pas créer de fichiers .retry
retry_files_enabled = False
# Logs
log_path = ./ansible.log
[privilege_escalation]
# Configuration sudo
become = True
become_method = sudo
become_user = root
become_ask_pass = False
[ssh_connection]
# Paramètres SSH
pipelining = True
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no
+236
View File
@@ -0,0 +1,236 @@
# Script PowerShell d'automatisation complète du déploiement Ansible
# Exécute toutes les étapes automatiquement
param(
[string]$ServerIP = "",
[string]$ServerUser = "",
[switch]$TestMode = $false
)
Write-Host "╔══════════════════════════════════════════════════════╗" -ForegroundColor Cyan
Write-Host "║ Déploiement Automatisé DockeZR via Ansible ║" -ForegroundColor Cyan
Write-Host "╚══════════════════════════════════════════════════════╝" -ForegroundColor Cyan
Write-Host ""
# Fonction pour afficher les messages colorés
function Write-Step {
param([string]$Message, [string]$Color = "Green")
Write-Host "$Message" -ForegroundColor $Color
}
function Write-Error-Custom {
param([string]$Message)
Write-Host "$Message" -ForegroundColor Red
}
function Write-Success {
param([string]$Message)
Write-Host "$Message" -ForegroundColor Green
}
# Étape 1: Vérifier WSL
Write-Step "Étape 1/8: Vérification de WSL..." "Cyan"
try {
$wslCheck = wsl --list --verbose 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Success "WSL est installé"
} else {
Write-Error-Custom "WSL n'est pas installé. Installation requise..."
Write-Host "Commande: wsl --install" -ForegroundColor Yellow
Write-Host "Redémarrage requis après installation" -ForegroundColor Yellow
exit 1
}
} catch {
Write-Error-Custom "Impossible de vérifier WSL"
exit 1
}
# Étape 2: Vérifier Ansible dans WSL
Write-Step "Étape 2/8: Vérification d'Ansible dans WSL..." "Cyan"
$ansibleCheck = wsl bash -c "which ansible" 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Step "Installation d'Ansible dans WSL..." "Yellow"
wsl bash -c "sudo apt update && sudo apt install -y ansible"
if ($LASTEXITCODE -eq 0) {
Write-Success "Ansible installé avec succès"
} else {
Write-Error-Custom "Échec de l'installation d'Ansible"
exit 1
}
} else {
$ansibleVersion = wsl bash -c "ansible --version | head -n1"
Write-Success "Ansible est installé: $ansibleVersion"
}
# Étape 3: Configuration de l'inventaire
Write-Step "Étape 3/8: Configuration de l'inventaire..." "Cyan"
if ($ServerIP -eq "" -or $ServerUser -eq "") {
Write-Host ""
Write-Host "Configuration du serveur:" -ForegroundColor Yellow
if ($ServerIP -eq "") {
$ServerIP = Read-Host "Entrez l'adresse IP du serveur"
}
if ($ServerUser -eq "") {
$ServerUser = Read-Host "Entrez le nom d'utilisateur SSH"
}
}
# Créer l'inventaire configuré
$inventoryContent = @"
# Inventaire Ansible pour le déploiement DockeZR - Configuré automatiquement
[production]
server ansible_host=$ServerIP ansible_user=$ServerUser ansible_ssh_private_key_file=../../sskdockerz/ssh-key-2025-10-16.key
[production:vars]
ansible_python_interpreter=/usr/bin/python3
"@
Set-Content -Path "inventory.ini" -Value $inventoryContent -Encoding UTF8
Write-Success "Inventaire configuré avec IP: $ServerIP et User: $ServerUser"
# Étape 4: Vérifier la clé SSH
Write-Step "Étape 4/8: Vérification de la clé SSH..." "Cyan"
$sshKeyPath = "..\..\sskdockerz\ssh-key-2025-10-16.key"
if (Test-Path $sshKeyPath) {
Write-Success "Clé SSH trouvée"
# Configurer les permissions dans WSL
$wslKeyPath = wsl wslpath -a "$PWD\..\..\sskdockerz\ssh-key-2025-10-16.key"
wsl chmod 600 "$wslKeyPath"
Write-Success "Permissions de la clé SSH configurées"
} else {
Write-Error-Custom "Clé SSH introuvable: $sshKeyPath"
exit 1
}
# Étape 5: Test de connexion SSH
Write-Step "Étape 5/8: Test de connexion au serveur..." "Cyan"
$wslPath = wsl wslpath -a "$PWD"
$pingResult = wsl bash -c "cd '$wslPath'; ansible all -i inventory.ini -m ping" 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Success "Connexion SSH réussie!"
} else {
Write-Error-Custom "Échec de la connexion SSH"
Write-Host "Résultat:" -ForegroundColor Yellow
Write-Host $pingResult
Write-Host ""
Write-Host "Vérifiez:" -ForegroundColor Yellow
Write-Host " 1. L'adresse IP est correcte: $ServerIP" -ForegroundColor Yellow
Write-Host " 2. Le serveur est accessible" -ForegroundColor Yellow
Write-Host " 3. La clé SSH est valide" -ForegroundColor Yellow
Write-Host " 4. L'utilisateur '$ServerUser' existe sur le serveur" -ForegroundColor Yellow
$continue = Read-Host "Voulez-vous continuer quand même? (o/N)"
if ($continue -ne "o" -and $continue -ne "O") {
exit 1
}
}
# Étape 6: Vérification de la syntaxe du playbook
Write-Step "Étape 6/8: Vérification de la syntaxe du playbook..." "Cyan"
$syntaxCheck = wsl bash -c "cd '$wslPath'; ansible-playbook deploy.yml --syntax-check" 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Success "Syntaxe du playbook validée"
} else {
Write-Error-Custom "Erreur de syntaxe dans le playbook"
Write-Host $syntaxCheck
exit 1
}
# Étape 7: Mode test ou déploiement réel
if ($TestMode) {
Write-Step "Étape 7/8: Mode TEST - Simulation du déploiement..." "Yellow"
Write-Host ""
Write-Host "Mode test activé. Exécution avec --check (dry-run)" -ForegroundColor Yellow
wsl bash -c "cd '$wslPath'; ansible-playbook -i inventory.ini deploy.yml --check -v"
} else {
Write-Step "Étape 7/8: Lancement du déploiement RÉEL..." "Cyan"
Write-Host ""
Write-Host "⚠️ ATTENTION: Le déploiement va maintenant commencer!" -ForegroundColor Yellow
Write-Host ""
Write-Host "Cela va:" -ForegroundColor White
Write-Host " - Installer Docker sur le serveur" -ForegroundColor White
Write-Host " - Cloner le repository" -ForegroundColor White
Write-Host " - Construire et démarrer les conteneurs" -ForegroundColor White
Write-Host ""
$confirm = Read-Host "Confirmer le déploiement? (o/N)"
if ($confirm -ne "o" -and $confirm -ne "O") {
Write-Host "Déploiement annulé" -ForegroundColor Yellow
exit 0
}
Write-Host ""
Write-Host "🚀 Déploiement en cours... (cela peut prendre 5-10 minutes)" -ForegroundColor Green
Write-Host ""
wsl bash -c "cd '$wslPath'; ansible-playbook -i inventory.ini deploy.yml -v"
}
# Étape 8: Résultats et vérifications
Write-Host ""
Write-Step "Étape 8/8: Vérifications finales..." "Cyan"
if ($LASTEXITCODE -eq 0) {
Write-Host ""
Write-Host "╔══════════════════════════════════════════════════════╗" -ForegroundColor Green
Write-Host "║ ✓ DÉPLOIEMENT RÉUSSI ! ║" -ForegroundColor Green
Write-Host "╚══════════════════════════════════════════════════════╝" -ForegroundColor Green
Write-Host ""
Write-Host "🌐 Accès aux services:" -ForegroundColor Cyan
Write-Host ""
Write-Host " Frontend: http://$ServerIP:3000" -ForegroundColor White
Write-Host " Backend API: http://$ServerIP:8001" -ForegroundColor White
Write-Host " Swagger Docs: http://$ServerIP:8001/docs" -ForegroundColor White
Write-Host " Prometheus: http://$ServerIP:9090" -ForegroundColor White
Write-Host " Grafana: http://$ServerIP:3001" -ForegroundColor White
Write-Host ""
Write-Host "📝 Prochaines étapes:" -ForegroundColor Yellow
Write-Host " 1. Ouvrir http://$ServerIP:3000 dans votre navigateur" -ForegroundColor White
Write-Host " 2. Tester l'API: http://$ServerIP:8001/docs" -ForegroundColor White
Write-Host " 3. Prendre des captures d'écran pour le livrable" -ForegroundColor White
Write-Host ""
# Test rapide des URLs
Write-Step "Test de connectivité aux services..." "Cyan"
try {
$frontendTest = Invoke-WebRequest -Uri "http://$ServerIP:3000" -TimeoutSec 5 -UseBasicParsing -ErrorAction SilentlyContinue
if ($frontendTest.StatusCode -eq 200) {
Write-Success "Frontend accessible ✓"
}
} catch {
Write-Host " Frontend: En attente de démarrage..." -ForegroundColor Yellow
}
try {
$backendTest = Invoke-WebRequest -Uri "http://$ServerIP:8001/docs" -TimeoutSec 5 -UseBasicParsing -ErrorAction SilentlyContinue
if ($backendTest.StatusCode -eq 200) {
Write-Success "Backend API accessible ✓"
}
} catch {
Write-Host " Backend: En attente de démarrage..." -ForegroundColor Yellow
}
Write-Host ""
Write-Host "Attendez 30-60 secondes que tous les services démarrent complètement." -ForegroundColor Yellow
} else {
Write-Host ""
Write-Host "╔══════════════════════════════════════════════════════╗" -ForegroundColor Red
Write-Host "║ ✗ ERREUR DE DÉPLOIEMENT ║" -ForegroundColor Red
Write-Host "╚══════════════════════════════════════════════════════╝" -ForegroundColor Red
Write-Host ""
Write-Host "Consultez les logs ci-dessus pour plus de détails." -ForegroundColor Yellow
Write-Host ""
Write-Host "Commandes de diagnostic:" -ForegroundColor Yellow
Write-Host " - Voir les logs Ansible: cat ansible.log" -ForegroundColor White
Write-Host " - SSH au serveur: ssh -i ../../sskdockerz/ssh-key-2025-10-16.key $ServerUser@$ServerIP" -ForegroundColor White
Write-Host " - Voir les conteneurs: docker ps" -ForegroundColor White
exit 1
}
Write-Host ""
Write-Host "Script terminé!" -ForegroundColor Cyan
+102
View File
@@ -0,0 +1,102 @@
# Deploiement direct via Docker avec inventaire cree dans le conteneur
$ServerIP = "141.253.118.141"
$ServerUser = "root"
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host " DEPLOIEMENT DOCKEZR - Methode Directe" -ForegroundColor Cyan
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
Write-Host "Serveur: $ServerIP" -ForegroundColor White
Write-Host "Utilisateur: $ServerUser" -ForegroundColor White
Write-Host ""
Write-Host "DEPLOIEMENT EN COURS..." -ForegroundColor Green
Write-Host "Duree estimee: 5-10 minutes" -ForegroundColor Yellow
Write-Host ""
# Script bash qui sera execute dans le conteneur
$bashScript = @"
#!/bin/sh
set -e
echo '=== Preparation de l inventaire ==='
cat > /tmp/hosts << 'EOF'
[production]
$ServerIP ansible_user=$ServerUser ansible_python_interpreter=/usr/bin/python3
[production:vars]
ansible_ssh_private_key_file=/ssh/ssh-key-2025-10-16.key
ansible_host_key_checking=False
EOF
echo '=== Configuration de la cle SSH ==='
chmod 600 /ssh/ssh-key-2025-10-16.key
echo '=== Test de connexion ==='
ansible -i /tmp/hosts all -m ping
echo '=== Execution du playbook ==='
ansible-playbook -i /tmp/hosts /ansible/deploy.yml -v
"@
# Sauvegarder le script bash
$bashScript | Out-File -FilePath "deploy-script.sh" -Encoding ASCII -NoNewline
Write-Host "Execution du deploiement Ansible..." -ForegroundColor Cyan
Write-Host "═══════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
docker run --rm `
-v "${PWD}:/ansible" `
-v "${PWD}\..\..\sskdockerz:/ssh" `
-v "${PWD}\deploy-script.sh:/tmp/deploy.sh" `
-w /ansible `
-e ANSIBLE_HOST_KEY_CHECKING=False `
cytopia/ansible:latest `
sh /tmp/deploy.sh
Write-Host ""
Write-Host "═══════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
if ($LASTEXITCODE -eq 0) {
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host " DEPLOIEMENT TERMINE AVEC SUCCES!" -ForegroundColor Green
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host ""
Write-Host "Vos services DockeZR sont maintenant en ligne:" -ForegroundColor Cyan
Write-Host ""
Write-Host " Frontend: http://$ServerIP`:3000" -ForegroundColor White
Write-Host " Backend API: http://$ServerIP`:8001" -ForegroundColor White
Write-Host " Swagger Docs: http://$ServerIP`:8001/docs" -ForegroundColor White
Write-Host " Prometheus: http://$ServerIP`:9090" -ForegroundColor White
Write-Host " Grafana: http://$ServerIP`:3001" -ForegroundColor White
Write-Host ""
Write-Host "Patience: Les services prennent 30-60 secondes" -ForegroundColor Yellow
Write-Host " pour demarrer completement." -ForegroundColor Yellow
Write-Host ""
Write-Host "Ouverture du frontend dans le navigateur..." -ForegroundColor Cyan
Start-Sleep -Seconds 2
Start-Process "http://$ServerIP`:3000"
Write-Host ""
Write-Host "CAPTURES D'ECRAN POUR LE TP7:" -ForegroundColor Yellow
Write-Host " 1. Cette fenetre PowerShell (deploiement reussi)" -ForegroundColor White
Write-Host " 2. http://$ServerIP`:3000 (application web)" -ForegroundColor White
Write-Host " 3. http://$ServerIP`:8001/docs (API Swagger)" -ForegroundColor White
Write-Host " 4. SSH au serveur puis: docker ps" -ForegroundColor White
Write-Host ""
# Nettoyage
Remove-Item "deploy-script.sh" -ErrorAction SilentlyContinue
} else {
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Red
Write-Host " ERREUR PENDANT LE DEPLOIEMENT" -ForegroundColor Red
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Red
Write-Host ""
Write-Host "Consultez les messages d'erreur ci-dessus." -ForegroundColor Yellow
Remove-Item "deploy-script.sh" -ErrorAction SilentlyContinue
}
+168
View File
@@ -0,0 +1,168 @@
# Script de deploiement via Docker (sans WSL Ubuntu)
# Utilise un conteneur Ansible pour deployer
param(
[string]$ServerIP = "",
[string]$ServerUser = ""
)
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host " Deploiement Ansible via Docker - DockeZR" -ForegroundColor Cyan
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
# Verifier que Docker est en cours d'execution
Write-Host "[1/7] Verification de Docker..." -ForegroundColor Cyan
$dockerCheck = docker version 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host " ERREUR - Docker n'est pas en cours d'execution" -ForegroundColor Red
Write-Host " Demarrez Docker Desktop puis reessayez" -ForegroundColor Yellow
exit 1
}
Write-Host " OK - Docker est actif" -ForegroundColor Green
# Demander les informations du serveur
if ($ServerIP -eq "") {
Write-Host ""
$ServerIP = Read-Host "Entrez l'adresse IP de votre serveur Linux"
}
if ($ServerUser -eq "") {
$ServerUser = Read-Host "Entrez le nom d'utilisateur SSH (ex: ubuntu, root)"
}
Write-Host ""
Write-Host "Configuration:" -ForegroundColor Yellow
Write-Host " Serveur: $ServerIP" -ForegroundColor White
Write-Host " Utilisateur: $ServerUser" -ForegroundColor White
Write-Host ""
# Creer l'inventaire
Write-Host "[2/7] Configuration de l'inventaire..." -ForegroundColor Cyan
$inventoryContent = @"
[production]
server ansible_host=$ServerIP ansible_user=$ServerUser ansible_ssh_private_key_file=/ansible/ssh-key
[production:vars]
ansible_python_interpreter=/usr/bin/python3
"@
Set-Content -Path "inventory.ini" -Value $inventoryContent -Encoding UTF8
Write-Host " OK - Inventaire configure" -ForegroundColor Green
# Verifier la cle SSH
Write-Host "[3/7] Verification de la cle SSH..." -ForegroundColor Cyan
$sshKeyPath = "..\..\sskdockerz\ssh-key-2025-10-16.key"
if (-not (Test-Path $sshKeyPath)) {
Write-Host " ERREUR - Cle SSH introuvable: $sshKeyPath" -ForegroundColor Red
exit 1
}
Write-Host " OK - Cle SSH trouvee" -ForegroundColor Green
# Test de connexion avec Docker
Write-Host "[4/7] Test de connexion SSH..." -ForegroundColor Cyan
$testResult = docker run --rm `
-v "${PWD}:/ansible" `
-v "${PWD}\..\..\sskdockerz:/ssh" `
-w /ansible `
cytopia/ansible:latest `
sh -c "chmod 600 /ssh/ssh-key-2025-10-16.key && ansible all -i inventory.ini --private-key=/ssh/ssh-key-2025-10-16.key -m ping" 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host " OK - Connexion SSH reussie!" -ForegroundColor Green
} else {
Write-Host " ERREUR - Connexion SSH echouee" -ForegroundColor Red
Write-Host ""
Write-Host "Verifiez:" -ForegroundColor Yellow
Write-Host " 1. L'adresse IP: $ServerIP" -ForegroundColor White
Write-Host " 2. L'utilisateur: $ServerUser" -ForegroundColor White
Write-Host " 3. La cle SSH est autorisee sur le serveur" -ForegroundColor White
Write-Host ""
$continue = Read-Host "Voulez-vous continuer quand meme? (o/N)"
if ($continue -ne "o" -and $continue -ne "O") {
Write-Host "Deploiement annule" -ForegroundColor Yellow
exit 1
}
}
# Verification syntaxe
Write-Host "[5/7] Verification de la syntaxe du playbook..." -ForegroundColor Cyan
$syntaxCheck = docker run --rm `
-v "${PWD}:/ansible" `
-w /ansible `
cytopia/ansible:latest `
ansible-playbook deploy.yml --syntax-check 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host " OK - Syntaxe validee" -ForegroundColor Green
} else {
Write-Host " ERREUR - Probleme de syntaxe" -ForegroundColor Red
Write-Host $syntaxCheck
exit 1
}
# Confirmation
Write-Host ""
Write-Host "[6/7] Pret pour le deploiement" -ForegroundColor Cyan
Write-Host ""
Write-Host "Le deploiement va:" -ForegroundColor Yellow
Write-Host " - Installer Docker sur le serveur" -ForegroundColor White
Write-Host " - Cloner le repository GitHub" -ForegroundColor White
Write-Host " - Construire et lancer l'application" -ForegroundColor White
Write-Host ""
Write-Host "Duree estimee: 5-10 minutes" -ForegroundColor Yellow
Write-Host ""
$confirm = Read-Host "Confirmer le deploiement? (o/N)"
if ($confirm -ne "o" -and $confirm -ne "O") {
Write-Host "Deploiement annule" -ForegroundColor Yellow
exit 0
}
# Deploiement
Write-Host ""
Write-Host "[7/7] Deploiement en cours via conteneur Ansible..." -ForegroundColor Green
Write-Host ""
Write-Host "Cela peut prendre 5-10 minutes..." -ForegroundColor Yellow
Write-Host ""
docker run --rm `
-v "${PWD}:/ansible" `
-v "${PWD}\..\..\sskdockerz:/ssh" `
-w /ansible `
cytopia/ansible:latest `
sh -c "chmod 600 /ssh/ssh-key-2025-10-16.key && ansible-playbook -i inventory.ini deploy.yml --private-key=/ssh/ssh-key-2025-10-16.key -v"
# Resultat
Write-Host ""
if ($LASTEXITCODE -eq 0) {
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host " DEPLOIEMENT REUSSI!" -ForegroundColor Green
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host ""
Write-Host "Acces aux services:" -ForegroundColor Cyan
Write-Host ""
Write-Host " Frontend: http://$ServerIP:3000" -ForegroundColor White
Write-Host " Backend API: http://$ServerIP:8001" -ForegroundColor White
Write-Host " Swagger: http://$ServerIP:8001/docs" -ForegroundColor White
Write-Host " Prometheus: http://$ServerIP:9090" -ForegroundColor White
Write-Host " Grafana: http://$ServerIP:3001" -ForegroundColor White
Write-Host ""
Write-Host "Attendez 30-60 secondes que tout demarre..." -ForegroundColor Yellow
Write-Host ""
$openBrowser = Read-Host "Voulez-vous ouvrir le frontend dans le navigateur? (o/N)"
if ($openBrowser -eq "o" -or $openBrowser -eq "O") {
Start-Process "http://$ServerIP:3000"
}
} else {
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Red
Write-Host " ERREUR DE DEPLOIEMENT" -ForegroundColor Red
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Red
Write-Host ""
Write-Host "Consultez les logs ci-dessus pour plus de details." -ForegroundColor Yellow
exit 1
}
+104
View File
@@ -0,0 +1,104 @@
# Deploiement avec image Ansible complete (avec SSH)
$ServerIP = "141.253.118.141"
$ServerUser = "root"
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host " DEPLOIEMENT DOCKEZR" -ForegroundColor Cyan
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
Write-Host "Serveur: $ServerIP" -ForegroundColor White
Write-Host "Utilisateur: $ServerUser" -ForegroundColor White
Write-Host ""
Write-Host "[1/3] Telechargement de l'image Ansible (si necessaire)..." -ForegroundColor Cyan
docker pull willhallonline/ansible:latest 2>&1 | Out-Null
Write-Host " OK" -ForegroundColor Green
Write-Host "[2/3] Test de connexion SSH..." -ForegroundColor Cyan
docker run --rm `
-v "${PWD}:/ansible" `
-v "${PWD}\..\..\sskdockerz:/ssh" `
-w /ansible `
-e ANSIBLE_HOST_KEY_CHECKING=False `
willhallonline/ansible:latest `
sh -c "chmod 600 /ssh/ssh-key-2025-10-16.key && ansible all -i '$ServerIP,' -u $ServerUser --private-key=/ssh/ssh-key-2025-10-16.key -m ping"
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Host "ERREUR: Impossible de se connecter au serveur" -ForegroundColor Red
Write-Host "Verifiez que le serveur $ServerIP est accessible" -ForegroundColor Yellow
Write-Host ""
Write-Host "Voulez-vous continuer quand meme? (o/N)" -ForegroundColor Yellow
$continue = Read-Host
if ($continue -ne "o" -and $continue -ne "O") {
exit 1
}
}
Write-Host " OK - Connexion reussie!" -ForegroundColor Green
Write-Host ""
Write-Host "[3/3] DEPLOIEMENT EN COURS..." -ForegroundColor Green
Write-Host ""
Write-Host "Cela va prendre 5-10 minutes" -ForegroundColor Yellow
Write-Host "Ne fermez pas cette fenetre!" -ForegroundColor Yellow
Write-Host "═══════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
docker run --rm `
-v "${PWD}:/ansible" `
-v "${PWD}\..\..\sskdockerz:/ssh" `
-w /ansible `
-e ANSIBLE_HOST_KEY_CHECKING=False `
willhallonline/ansible:latest `
sh -c "chmod 600 /ssh/ssh-key-2025-10-16.key && ansible-playbook deploy.yml -i '$ServerIP,' -u $ServerUser --private-key=/ssh/ssh-key-2025-10-16.key"
Write-Host ""
Write-Host "═══════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
if ($LASTEXITCODE -eq 0) {
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host " DEPLOIEMENT TERMINE AVEC SUCCES!" -ForegroundColor Green
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host ""
Write-Host "Vos services DockeZR sont maintenant en ligne:" -ForegroundColor Cyan
Write-Host ""
Write-Host " Frontend: http://$ServerIP`:3000" -ForegroundColor White
Write-Host " Backend API: http://$ServerIP`:8001" -ForegroundColor White
Write-Host " Swagger Docs: http://$ServerIP`:8001/docs" -ForegroundColor White
Write-Host " Prometheus: http://$ServerIP`:9090" -ForegroundColor White
Write-Host " Grafana: http://$ServerIP`:3001" -ForegroundColor White
Write-Host ""
Write-Host "NOTE: Les services prennent 30-60 secondes" -ForegroundColor Yellow
Write-Host " pour demarrer completement." -ForegroundColor Yellow
Write-Host ""
Write-Host "Ouverture du frontend dans le navigateur..." -ForegroundColor Cyan
Start-Sleep -Seconds 3
Start-Process "http://$ServerIP`:3000"
Write-Host ""
Write-Host "═══════════════════════════════════════════════════════" -ForegroundColor Yellow
Write-Host " CAPTURES D'ECRAN POUR LE TP7" -ForegroundColor Yellow
Write-Host "═══════════════════════════════════════════════════════" -ForegroundColor Yellow
Write-Host ""
Write-Host "Prenez ces captures:" -ForegroundColor White
Write-Host " 1. Cette fenetre PowerShell (deploiement reussi)" -ForegroundColor White
Write-Host " 2. http://$ServerIP`:3000 (application web)" -ForegroundColor White
Write-Host " 3. http://$ServerIP`:8001/docs (API Swagger)" -ForegroundColor White
Write-Host " 4. SSH au serveur: docker ps" -ForegroundColor White
Write-Host ""
Write-Host "Pour vous connecter au serveur:" -ForegroundColor Cyan
Write-Host " ssh -i ..\..\sskdockerz\ssh-key-2025-10-16.key $ServerUser@$ServerIP" -ForegroundColor White
Write-Host " Puis sur le serveur: docker ps" -ForegroundColor White
Write-Host ""
} else {
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Red
Write-Host " ERREUR PENDANT LE DEPLOIEMENT" -ForegroundColor Red
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Red
Write-Host ""
Write-Host "Consultez les messages d'erreur ci-dessus." -ForegroundColor Yellow
}
+103
View File
@@ -0,0 +1,103 @@
# Deploiement corrige avec inventaire simplifie
$ServerIP = "141.253.118.141"
$ServerUser = "root"
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host " DEPLOIEMENT DOCKEZR - Version Corrigee" -ForegroundColor Cyan
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
Write-Host "Serveur: $ServerIP" -ForegroundColor White
Write-Host "Utilisateur: $ServerUser" -ForegroundColor White
Write-Host ""
Write-Host "DEPLOIEMENT EN COURS..." -ForegroundColor Green
Write-Host "Cela va prendre 5-10 minutes" -ForegroundColor Yellow
Write-Host ""
# Verifier que la cle existe
if (-not (Test-Path "..\..\sskdockerz\ssh-key-2025-10-16.key")) {
Write-Host "ERREUR: Cle SSH introuvable!" -ForegroundColor Red
exit 1
}
Write-Host "[1/3] Preparation de l'inventaire..." -ForegroundColor Cyan
$inventoryContent = "[production]`n$ServerIP ansible_user=$ServerUser ansible_ssh_private_key_file=/ssh/ssh-key-2025-10-16.key ansible_python_interpreter=/usr/bin/python3 ansible_host_key_checking=false"
Set-Content -Path "inventory.ini" -Value $inventoryContent -Encoding UTF8 -NoNewline
Write-Host " OK" -ForegroundColor Green
Write-Host "[2/3] Test de connexion..." -ForegroundColor Cyan
$testCmd = docker run --rm `
-v "${PWD}:/ansible" `
-v "${PWD}\..\..\sskdockerz:/ssh" `
-w /ansible `
-e ANSIBLE_HOST_KEY_CHECKING=False `
cytopia/ansible:latest `
sh -c "chmod 600 /ssh/ssh-key-2025-10-16.key && ansible -i inventory.ini all -m ping --private-key=/ssh/ssh-key-2025-10-16.key" 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host " OK - Connexion reussie" -ForegroundColor Green
} else {
Write-Host " ATTENTION - Probleme de connexion mais on continue..." -ForegroundColor Yellow
}
Write-Host "[3/3] Execution du playbook Ansible..." -ForegroundColor Cyan
Write-Host ""
Write-Host "Cela peut prendre plusieurs minutes..." -ForegroundColor Yellow
Write-Host "═══════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
docker run --rm `
-v "${PWD}:/ansible" `
-v "${PWD}\..\..\sskdockerz:/ssh" `
-w /ansible `
-e ANSIBLE_HOST_KEY_CHECKING=False `
cytopia/ansible:latest `
sh -c "chmod 600 /ssh/ssh-key-2025-10-16.key && ansible-playbook -i inventory.ini deploy.yml --private-key=/ssh/ssh-key-2025-10-16.key"
Write-Host ""
Write-Host "═══════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
if ($LASTEXITCODE -eq 0) {
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host " DEPLOIEMENT TERMINE AVEC SUCCES!" -ForegroundColor Green
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host ""
Write-Host "Vos services DockeZR sont maintenant en ligne:" -ForegroundColor Cyan
Write-Host ""
Write-Host " Frontend: http://$ServerIP`:3000" -ForegroundColor White
Write-Host " Backend API: http://$ServerIP`:8001" -ForegroundColor White
Write-Host " Swagger Docs: http://$ServerIP`:8001/docs" -ForegroundColor White
Write-Host " Prometheus: http://$ServerIP`:9090" -ForegroundColor White
Write-Host " Grafana: http://$ServerIP`:3001" -ForegroundColor White
Write-Host ""
Write-Host "Patience: Les services peuvent prendre 30-60 secondes" -ForegroundColor Yellow
Write-Host " pour demarrer completement." -ForegroundColor Yellow
Write-Host ""
Write-Host "Ouverture du frontend..." -ForegroundColor Cyan
Start-Sleep -Seconds 3
Start-Process "http://$ServerIP`:3000"
Write-Host ""
Write-Host "Pour les captures d'ecran du TP7:" -ForegroundColor Yellow
Write-Host " 1. Cette fenetre (deploiement reussi)" -ForegroundColor White
Write-Host " 2. http://$ServerIP`:3000 (application web)" -ForegroundColor White
Write-Host " 3. http://$ServerIP`:8001/docs (API Swagger)" -ForegroundColor White
Write-Host " 4. SSH au serveur: docker ps" -ForegroundColor White
Write-Host ""
} else {
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Red
Write-Host " ERREUR PENDANT LE DEPLOIEMENT" -ForegroundColor Red
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Red
Write-Host ""
Write-Host "Consultez les messages d'erreur ci-dessus." -ForegroundColor Yellow
Write-Host ""
Write-Host "Solutions possibles:" -ForegroundColor Yellow
Write-Host " - Verifier que le serveur est accessible" -ForegroundColor White
Write-Host " - Verifier les permissions SSH" -ForegroundColor White
Write-Host " - Verifier que root peut faire sudo" -ForegroundColor White
Write-Host ""
}
+140
View File
@@ -0,0 +1,140 @@
# Script de deploiement interactif simplifie
param(
[string]$ServerIP = "",
[string]$ServerUser = ""
)
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host " Deploiement Ansible - DockeZR" -ForegroundColor Cyan
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
# Demander les informations si non fournies
if ($ServerIP -eq "") {
$ServerIP = Read-Host "Entrez l'adresse IP du serveur"
}
if ($ServerUser -eq "") {
$ServerUser = Read-Host "Entrez le nom d'utilisateur SSH (ex: ubuntu, root)"
}
Write-Host ""
Write-Host "Configuration:" -ForegroundColor Yellow
Write-Host " Serveur: $ServerIP" -ForegroundColor White
Write-Host " Utilisateur: $ServerUser" -ForegroundColor White
Write-Host ""
# Creer l'inventaire
Write-Host "[1/6] Configuration de l'inventaire..." -ForegroundColor Cyan
$inventoryContent = @"
# Inventaire Ansible - Configure automatiquement
[production]
server ansible_host=$ServerIP ansible_user=$ServerUser ansible_ssh_private_key_file=../../sskdockerz/ssh-key-2025-10-16.key
[production:vars]
ansible_python_interpreter=/usr/bin/python3
"@
Set-Content -Path "inventory.ini" -Value $inventoryContent -Encoding UTF8
Write-Host " OK - Inventaire cree" -ForegroundColor Green
# Configurer les permissions SSH
Write-Host "[2/6] Configuration de la cle SSH..." -ForegroundColor Cyan
$wslKeyPath = wsl wslpath -a "$PWD\..\..\sskdockerz\ssh-key-2025-10-16.key"
wsl chmod 600 "$wslKeyPath"
Write-Host " OK - Permissions configurees" -ForegroundColor Green
# Test de connexion
Write-Host "[3/6] Test de connexion SSH..." -ForegroundColor Cyan
$wslPath = wsl wslpath -a "$PWD"
$pingResult = wsl bash -c "cd '$wslPath'; ansible all -i inventory.ini -m ping" 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host " OK - Connexion SSH reussie!" -ForegroundColor Green
} else {
Write-Host " ERREUR - Connexion SSH echouee" -ForegroundColor Red
Write-Host ""
Write-Host "Verifiez:" -ForegroundColor Yellow
Write-Host " 1. L'adresse IP: $ServerIP" -ForegroundColor White
Write-Host " 2. L'utilisateur: $ServerUser" -ForegroundColor White
Write-Host " 3. La cle SSH est valide" -ForegroundColor White
Write-Host " 4. Le serveur est accessible" -ForegroundColor White
Write-Host ""
$continue = Read-Host "Voulez-vous continuer quand meme? (o/N)"
if ($continue -ne "o" -and $continue -ne "O") {
Write-Host "Deploiement annule" -ForegroundColor Yellow
exit 1
}
}
# Verification syntaxe
Write-Host "[4/6] Verification de la syntaxe..." -ForegroundColor Cyan
$syntaxCheck = wsl bash -c "cd '$wslPath'; ansible-playbook deploy.yml --syntax-check" 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host " OK - Syntaxe validee" -ForegroundColor Green
} else {
Write-Host " ERREUR - Probleme de syntaxe" -ForegroundColor Red
Write-Host $syntaxCheck
exit 1
}
# Confirmation
Write-Host ""
Write-Host "[5/6] Pret pour le deploiement" -ForegroundColor Cyan
Write-Host ""
Write-Host "Le deploiement va:" -ForegroundColor Yellow
Write-Host " - Installer Docker sur le serveur" -ForegroundColor White
Write-Host " - Cloner le repository GitHub" -ForegroundColor White
Write-Host " - Construire et lancer l'application" -ForegroundColor White
Write-Host ""
Write-Host "Duree estimee: 5-10 minutes" -ForegroundColor Yellow
Write-Host ""
$confirm = Read-Host "Confirmer le deploiement? (o/N)"
if ($confirm -ne "o" -and $confirm -ne "O") {
Write-Host "Deploiement annule" -ForegroundColor Yellow
exit 0
}
# Deploiement
Write-Host ""
Write-Host "[6/6] Deploiement en cours..." -ForegroundColor Green
Write-Host ""
wsl bash -c "cd '$wslPath'; ansible-playbook -i inventory.ini deploy.yml"
# Resultat
Write-Host ""
if ($LASTEXITCODE -eq 0) {
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host " DEPLOIEMENT REUSSI!" -ForegroundColor Green
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host ""
Write-Host "Acces aux services:" -ForegroundColor Cyan
Write-Host ""
Write-Host " Frontend: http://$ServerIP:3000" -ForegroundColor White
Write-Host " Backend API: http://$ServerIP:8001" -ForegroundColor White
Write-Host " Swagger: http://$ServerIP:8001/docs" -ForegroundColor White
Write-Host " Prometheus: http://$ServerIP:9090" -ForegroundColor White
Write-Host " Grafana: http://$ServerIP:3001" -ForegroundColor White
Write-Host ""
Write-Host "Attendez 30-60 secondes que tout demarre..." -ForegroundColor Yellow
Write-Host ""
# Ouvrir le navigateur
$openBrowser = Read-Host "Voulez-vous ouvrir le frontend dans le navigateur? (o/N)"
if ($openBrowser -eq "o" -or $openBrowser -eq "O") {
Start-Process "http://$ServerIP:3000"
}
} else {
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Red
Write-Host " ERREUR DE DEPLOIEMENT" -ForegroundColor Red
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Red
Write-Host ""
Write-Host "Consultez les logs ci-dessus pour plus de details." -ForegroundColor Yellow
exit 1
}
+116
View File
@@ -0,0 +1,116 @@
# Deploiement manuel sur le serveur via SSH
$ServerIP = "141.253.118.141"
$ServerUser = "root"
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host " DEPLOIEMENT MANUEL DOCKEZR" -ForegroundColor Cyan
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
Write-Host "Serveur: $ServerIP" -ForegroundColor White
Write-Host ""
# Fonction pour executer des commandes SSH
function Invoke-SSHCommand {
param([string]$Command)
docker run --rm -v "${PWD}\..\..\sskdockerz:/ssh" willhallonline/ansible:latest sh -c "chmod 600 /ssh/ssh-key-2025-10-16.key && ssh -o StrictHostKeyChecking=no -i /ssh/ssh-key-2025-10-16.key $ServerUser@$ServerIP '$Command'"
}
Write-Host "[1/8] Installation de Docker..." -ForegroundColor Cyan
Invoke-SSHCommand "apt update && apt install -y docker.io docker-compose git curl"
if ($LASTEXITCODE -eq 0) {
Write-Host " OK - Docker installe" -ForegroundColor Green
} else {
Write-Host " Erreur lors de l'installation" -ForegroundColor Red
}
Write-Host "[2/8] Demarrage du service Docker..." -ForegroundColor Cyan
Invoke-SSHCommand "systemctl start docker && systemctl enable docker"
Write-Host " OK" -ForegroundColor Green
Write-Host "[3/8] Verification de Docker..." -ForegroundColor Cyan
Invoke-SSHCommand "docker --version"
Write-Host " OK" -ForegroundColor Green
Write-Host "[4/8] Creation du repertoire de deploiement..." -ForegroundColor Cyan
Invoke-SSHCommand "mkdir -p /opt/dockezr"
Write-Host " OK" -ForegroundColor Green
Write-Host "[5/8] Clonage du repository (depuis votre machine)..." -ForegroundColor Cyan
Write-Host " Copie des fichiers vers le serveur..." -ForegroundColor Yellow
# On va copier les fichiers necessaires via SSH
docker run --rm `
-v "${PWD}\..:/project" `
-v "${PWD}\..\..\sskdockerz:/ssh" `
-w /project `
willhallonline/ansible:latest `
sh -c "chmod 600 /ssh/ssh-key-2025-10-16.key && tar czf - dockezr | ssh -o StrictHostKeyChecking=no -i /ssh/ssh-key-2025-10-16.key $ServerUser@$ServerIP 'cd /opt && tar xzf -'"
Write-Host " OK - Fichiers copies" -ForegroundColor Green
Write-Host "[6/8] Creation du fichier .env..." -ForegroundColor Cyan
$envContent = @"
POSTGRES_USER=dockezr_user
POSTGRES_PASSWORD=dockezr_password_2024
POSTGRES_DB=dockezr
DB_PORT=5432
BACKEND_PORT=8001
FRONTEND_PORT=3000
PROMETHEUS_PORT=9090
GRAFANA_PORT=3001
NEXT_PUBLIC_API_URL=http://$ServerIP:8001
GRAFANA_USER=admin
GRAFANA_PASSWORD=admin123
NODE_ENV=production
"@
$envContent | Out-File -FilePath "temp.env" -Encoding ASCII -NoNewline
docker run --rm `
-v "${PWD}\temp.env:/tmp/env" `
-v "${PWD}\..\..\sskdockerz:/ssh" `
willhallonline/ansible:latest `
sh -c "chmod 600 /ssh/ssh-key-2025-10-16.key && cat /tmp/env | ssh -o StrictHostKeyChecking=no -i /ssh/ssh-key-2025-10-16.key $ServerUser@$ServerIP 'cat > /opt/dockezr/.env'"
Remove-Item "temp.env" -ErrorAction SilentlyContinue
Write-Host " OK - Environnement configure" -ForegroundColor Green
Write-Host "[7/8] Lancement des conteneurs Docker..." -ForegroundColor Cyan
Write-Host " Cela peut prendre quelques minutes..." -ForegroundColor Yellow
Invoke-SSHCommand "cd /opt/dockezr && docker-compose up -d --build"
Write-Host " OK - Conteneurs lances" -ForegroundColor Green
Start-Sleep -Seconds 5
Write-Host "[8/8] Verification des conteneurs..." -ForegroundColor Cyan
Write-Host ""
Invoke-SSHCommand "docker ps"
Write-Host ""
if ($LASTEXITCODE -eq 0) {
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host " DEPLOIEMENT REUSSI!" -ForegroundColor Green
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host ""
Write-Host "Vos services DockeZR sont maintenant en ligne:" -ForegroundColor Cyan
Write-Host ""
Write-Host " Frontend: http://$ServerIP`:3000" -ForegroundColor White
Write-Host " Backend API: http://$ServerIP`:8001" -ForegroundColor White
Write-Host " Swagger Docs: http://$ServerIP`:8001/docs" -ForegroundColor White
Write-Host " Prometheus: http://$ServerIP`:9090" -ForegroundColor White
Write-Host " Grafana: http://$ServerIP`:3001" -ForegroundColor White
Write-Host ""
Write-Host "Attendez 30-60 secondes que tout demarre..." -ForegroundColor Yellow
Write-Host ""
Write-Host "Ouverture du frontend..." -ForegroundColor Cyan
Start-Sleep -Seconds 3
Start-Process "http://$ServerIP`:3000"
Write-Host ""
Write-Host "CAPTURES D'ECRAN POUR LE TP7:" -ForegroundColor Yellow
Write-Host " 1. Cette fenetre PowerShell" -ForegroundColor White
Write-Host " 2. http://$ServerIP`:3000" -ForegroundColor White
Write-Host " 3. http://$ServerIP`:8001/docs" -ForegroundColor White
Write-Host ""
}
+67
View File
@@ -0,0 +1,67 @@
# Deploiement automatique SANS confirmation
# Lance directement le deploiement
$ServerIP = "141.253.118.141"
$ServerUser = "root"
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host " DEPLOIEMENT AUTOMATIQUE - DockeZR" -ForegroundColor Cyan
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
Write-Host "Serveur: $ServerIP" -ForegroundColor White
Write-Host "Utilisateur: $ServerUser" -ForegroundColor White
Write-Host ""
Write-Host "DEPLOIEMENT EN COURS..." -ForegroundColor Green
Write-Host "Cela peut prendre 5-10 minutes" -ForegroundColor Yellow
Write-Host ""
# Configurer l'inventaire
$inventoryContent = @"
[production]
server ansible_host=$ServerIP ansible_user=$ServerUser ansible_ssh_private_key_file=/ssh/ssh-key-2025-10-16.key
[production:vars]
ansible_python_interpreter=/usr/bin/python3
"@
Set-Content -Path "inventory.ini" -Value $inventoryContent -Encoding UTF8
# Lancer le deploiement avec Docker
Write-Host "Execution du playbook Ansible..." -ForegroundColor Cyan
Write-Host ""
docker run --rm `
-v "${PWD}:/ansible" `
-v "${PWD}\..\..\sskdockerz:/ssh" `
-w /ansible `
cytopia/ansible:latest `
sh -c "chmod 600 /ssh/ssh-key-2025-10-16.key && ansible-playbook -i inventory.ini deploy.yml --private-key=/ssh/ssh-key-2025-10-16.key -v"
# Resultat
Write-Host ""
if ($LASTEXITCODE -eq 0) {
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host " DEPLOIEMENT REUSSI!" -ForegroundColor Green
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host ""
Write-Host "Vos services sont maintenant accessibles:" -ForegroundColor Cyan
Write-Host ""
Write-Host " Frontend: http://$ServerIP`:3000" -ForegroundColor White
Write-Host " Backend API: http://$ServerIP`:8001" -ForegroundColor White
Write-Host " Swagger: http://$ServerIP`:8001/docs" -ForegroundColor White
Write-Host " Prometheus: http://$ServerIP`:9090" -ForegroundColor White
Write-Host " Grafana: http://$ServerIP`:3001" -ForegroundColor White
Write-Host ""
Write-Host "Attendez 30-60 secondes que tous les services demarrent" -ForegroundColor Yellow
Write-Host ""
Write-Host "Ouverture du frontend dans le navigateur..." -ForegroundColor Cyan
Start-Sleep -Seconds 2
Start-Process "http://$ServerIP`:3000"
} else {
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Red
Write-Host " ERREUR DE DEPLOIEMENT" -ForegroundColor Red
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Red
Write-Host ""
Write-Host "Consultez les logs ci-dessus" -ForegroundColor Yellow
}
+90
View File
@@ -0,0 +1,90 @@
# Deploiement simplifie - directement en ligne de commande
$ServerIP = "141.253.118.141"
$ServerUser = "root"
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host " DEPLOIEMENT DOCKEZR - Version Simplifiee" -ForegroundColor Cyan
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
Write-Host "Serveur: $ServerIP" -ForegroundColor White
Write-Host "Utilisateur: $ServerUser" -ForegroundColor White
Write-Host ""
Write-Host "[1/2] Test de connexion SSH..." -ForegroundColor Cyan
docker run --rm `
-v "${PWD}:/ansible" `
-v "${PWD}\..\..\sskdockerz:/ssh" `
-w /ansible `
-e ANSIBLE_HOST_KEY_CHECKING=False `
cytopia/ansible:latest `
sh -c "chmod 600 /ssh/ssh-key-2025-10-16.key && ansible all -i '$ServerIP,' -u $ServerUser --private-key=/ssh/ssh-key-2025-10-16.key -m ping"
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Host "ERREUR: Impossible de se connecter au serveur" -ForegroundColor Red
Write-Host "Verifiez que le serveur $ServerIP est accessible" -ForegroundColor Yellow
exit 1
}
Write-Host " OK - Connexion reussie!" -ForegroundColor Green
Write-Host ""
Write-Host "[2/2] Lancement du deploiement Ansible..." -ForegroundColor Cyan
Write-Host ""
Write-Host "DEPLOIEMENT EN COURS..." -ForegroundColor Green
Write-Host "Cela va prendre 5-10 minutes" -ForegroundColor Yellow
Write-Host "═══════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
docker run --rm `
-v "${PWD}:/ansible" `
-v "${PWD}\..\..\sskdockerz:/ssh" `
-w /ansible `
-e ANSIBLE_HOST_KEY_CHECKING=False `
cytopia/ansible:latest `
sh -c "chmod 600 /ssh/ssh-key-2025-10-16.key && ansible-playbook deploy.yml -i '$ServerIP,' -u $ServerUser --private-key=/ssh/ssh-key-2025-10-16.key"
Write-Host ""
Write-Host "═══════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
if ($LASTEXITCODE -eq 0) {
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host " DEPLOIEMENT TERMINE AVEC SUCCES!" -ForegroundColor Green
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host ""
Write-Host "Vos services DockeZR sont maintenant en ligne:" -ForegroundColor Cyan
Write-Host ""
Write-Host " Frontend: http://$ServerIP`:3000" -ForegroundColor White
Write-Host " Backend API: http://$ServerIP`:8001" -ForegroundColor White
Write-Host " Swagger Docs: http://$ServerIP`:8001/docs" -ForegroundColor White
Write-Host " Prometheus: http://$ServerIP`:9090" -ForegroundColor White
Write-Host " Grafana: http://$ServerIP`:3001" -ForegroundColor White
Write-Host ""
Write-Host "NOTE: Les services prennent 30-60 secondes" -ForegroundColor Yellow
Write-Host " pour demarrer completement." -ForegroundColor Yellow
Write-Host ""
Write-Host "Ouverture du frontend dans le navigateur..." -ForegroundColor Cyan
Start-Sleep -Seconds 2
Start-Process "http://$ServerIP`:3000"
Write-Host ""
Write-Host "CAPTURES D'ECRAN POUR LE TP7:" -ForegroundColor Yellow
Write-Host " 1. Cette fenetre PowerShell" -ForegroundColor White
Write-Host " 2. http://$ServerIP`:3000" -ForegroundColor White
Write-Host " 3. http://$ServerIP`:8001/docs" -ForegroundColor White
Write-Host " 4. Connectez-vous en SSH et faites: docker ps" -ForegroundColor White
Write-Host ""
Write-Host "Commande SSH:" -ForegroundColor Cyan
Write-Host " ssh -i ..\..\sskdockerz\ssh-key-2025-10-16.key $ServerUser@$ServerIP" -ForegroundColor White
Write-Host ""
} else {
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Red
Write-Host " ERREUR PENDANT LE DEPLOIEMENT" -ForegroundColor Red
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Red
Write-Host ""
Write-Host "Consultez les messages d'erreur ci-dessus." -ForegroundColor Yellow
}
+85
View File
@@ -0,0 +1,85 @@
#!/bin/bash
# Script de déploiement Ansible pour DockeZR
# À exécuter depuis WSL ou Linux
# Couleurs pour l'affichage
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${BLUE}╔══════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ Déploiement Ansible - DockeZR ║${NC}"
echo -e "${BLUE}╚══════════════════════════════════════╝${NC}"
echo ""
# Vérifier qu'Ansible est installé
if ! command -v ansible &> /dev/null; then
echo -e "${RED}❌ Ansible n'est pas installé!${NC}"
echo ""
echo "Installation sur Ubuntu/Debian:"
echo " sudo apt update && sudo apt install ansible -y"
echo ""
exit 1
fi
echo -e "${GREEN}✅ Ansible version: $(ansible --version | head -n1)${NC}"
echo ""
# Test de connexion
echo -e "${YELLOW}🔍 Test de connexion SSH...${NC}"
if ansible all -i inventory.ini -m ping &> /dev/null; then
echo -e "${GREEN}✅ Connexion SSH réussie!${NC}"
echo ""
else
echo -e "${RED}❌ Impossible de se connecter au serveur!${NC}"
echo ""
echo "Vérifiez:"
echo " 1. L'adresse IP dans inventory.ini"
echo " 2. Les permissions de la clé SSH: chmod 600 ../../sskdockerz/ssh-key-2025-10-16.key"
echo " 3. La connexion réseau"
echo ""
exit 1
fi
# Menu de déploiement
echo -e "${BLUE}Choisissez une option:${NC}"
echo " 1) Déploiement complet (recommandé)"
echo " 2) Test de connexion uniquement"
echo " 3) Arrêter les conteneurs"
echo " 4) Reconstruire et redémarrer"
echo " 5) Mode verbeux (debug)"
echo ""
read -p "Votre choix [1-5]: " choice
case $choice in
1)
echo -e "${GREEN}🚀 Lancement du déploiement complet...${NC}"
ansible-playbook -i inventory.ini deploy.yml
;;
2)
echo -e "${GREEN}🔍 Test de connexion...${NC}"
ansible all -i inventory.ini -m ping -v
;;
3)
echo -e "${YELLOW}🛑 Arrêt des conteneurs...${NC}"
ansible-playbook -i inventory.ini deploy.yml --tags stop
;;
4)
echo -e "${GREEN}🔄 Reconstruction et redémarrage...${NC}"
ansible-playbook -i inventory.ini deploy.yml --tags build,start
;;
5)
echo -e "${GREEN}🐛 Mode verbeux activé...${NC}"
ansible-playbook -i inventory.ini deploy.yml -vvv
;;
*)
echo -e "${RED}Choix invalide!${NC}"
exit 1
;;
esac
echo ""
echo -e "${GREEN}✅ Opération terminée!${NC}"
+234
View File
@@ -0,0 +1,234 @@
---
# Playbook Ansible pour déployer DockeZR
# Ce playbook installe Docker, clone le repository et lance l'application
- name: "Déploiement automatisé de DockeZR sur serveur Linux"
hosts: all
become: yes
gather_facts: yes
tasks:
# ====================================================================
# ÉTAPE 1 : Mise à jour du système et installation des prérequis
# ====================================================================
- name: "[1/10] 🔄 Mise à jour du cache APT"
apt:
update_cache: yes
cache_valid_time: 3600
when: ansible_os_family == "Debian"
- name: "[1/10] 📦 Installation des paquets système requis"
apt:
name:
- apt-transport-https
- ca-certificates
- curl
- gnupg
- lsb-release
- git
- python3
- python3-pip
state: present
when: ansible_os_family == "Debian"
# ====================================================================
# ÉTAPE 2 : Installation de Docker
# ====================================================================
- name: "[2/10] 🐳 Vérification si Docker est déjà installé"
command: docker --version
register: docker_installed
ignore_errors: yes
changed_when: false
- name: "[2/10] 📁 Création du répertoire pour les clés GPG"
file:
path: /etc/apt/keyrings
state: directory
mode: '0755'
when: docker_installed.rc != 0
- name: "[2/10] 🔑 Ajout de la clé GPG officielle de Docker"
shell: |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
args:
creates: /etc/apt/keyrings/docker.gpg
when: docker_installed.rc != 0 and ansible_distribution == "Ubuntu"
- name: "[2/10] 📝 Ajout du repository Docker"
apt_repository:
repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
state: present
filename: docker
when: docker_installed.rc != 0 and ansible_distribution == "Ubuntu"
- name: "[2/10] 🐳 Installation de Docker Engine"
apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
state: present
update_cache: yes
when: docker_installed.rc != 0
- name: "[2/10] ✅ Vérification que Docker est démarré et activé au boot"
systemd:
name: docker
state: started
enabled: yes
- name: "[2/10] 👤 Ajout de l'utilisateur au groupe docker"
user:
name: "{{ deploy_user }}"
groups: docker
append: yes
# ====================================================================
# ÉTAPE 3 : Installation de Docker Compose (si nécessaire)
# ====================================================================
- name: "[3/10] 🔍 Vérification de Docker Compose"
command: docker compose version
register: compose_check
ignore_errors: yes
changed_when: false
- name: "[3/10] ✅ Docker Compose est installé"
debug:
msg: "Docker Compose est déjà disponible via le plugin Docker"
when: compose_check.rc == 0
# ====================================================================
# ÉTAPE 4 : Préparation des répertoires
# ====================================================================
- name: "[4/10] 📁 Création du répertoire de déploiement"
file:
path: "{{ deploy_dir }}"
state: directory
owner: "{{ deploy_user }}"
group: "{{ deploy_user }}"
mode: '0755'
# ====================================================================
# ÉTAPE 5 : Clonage du repository Git
# ====================================================================
- name: "[5/10] 🔍 Vérification si le repository existe déjà"
stat:
path: "{{ deploy_dir }}/.git"
register: git_repo
- name: "[5/10] 📥 Clonage du repository GitHub"
git:
repo: "{{ project_repo }}"
dest: "{{ deploy_dir }}"
version: "{{ project_branch }}"
force: yes
become_user: "{{ deploy_user }}"
when: not git_repo.stat.exists
- name: "[5/10] 🔄 Mise à jour du repository existant"
git:
repo: "{{ project_repo }}"
dest: "{{ deploy_dir }}"
version: "{{ project_branch }}"
force: yes
become_user: "{{ deploy_user }}"
when: git_repo.stat.exists
# ====================================================================
# ÉTAPE 6 : Configuration des variables d'environnement
# ====================================================================
- name: "[6/10] ⚙️ Création du fichier .env.prod depuis le template"
template:
src: templates/env.prod.j2
dest: "{{ deploy_dir }}/.env.prod"
owner: "{{ deploy_user }}"
group: "{{ deploy_user }}"
mode: '0600'
# ====================================================================
# ÉTAPE 7 : Arrêt des conteneurs existants (si présents)
# ====================================================================
- name: "[7/10] 🛑 Arrêt des conteneurs existants (si présents)"
command: docker compose -f docker-compose.prod.yml down
args:
chdir: "{{ deploy_dir }}"
become_user: "{{ deploy_user }}"
ignore_errors: yes
tags: stop
# ====================================================================
# ÉTAPE 8 : Construction des images Docker
# ====================================================================
- name: "[8/10] 🏗️ Construction des images Docker"
command: docker compose -f docker-compose.prod.yml build --no-cache
args:
chdir: "{{ deploy_dir }}"
become_user: "{{ deploy_user }}"
tags: build
# ====================================================================
# ÉTAPE 9 : Démarrage des conteneurs
# ====================================================================
- name: "[9/10] 🚀 Démarrage des conteneurs en arrière-plan"
command: docker compose -f docker-compose.prod.yml up -d
args:
chdir: "{{ deploy_dir }}"
become_user: "{{ deploy_user }}"
tags: start
# ====================================================================
# ÉTAPE 10 : Vérification du déploiement
# ====================================================================
- name: "[10/10] ⏳ Attente du démarrage des services (30 secondes)"
pause:
seconds: 30
- name: "[10/10] 🔍 Vérification de l'état des conteneurs"
command: docker compose -f docker-compose.prod.yml ps
args:
chdir: "{{ deploy_dir }}"
become_user: "{{ deploy_user }}"
register: containers_status
changed_when: false
- name: "[10/10] 📊 Affichage de l'état des conteneurs"
debug:
var: containers_status.stdout_lines
- name: "[10/10] 📝 Récupération des logs récents"
command: docker compose -f docker-compose.prod.yml logs --tail=20
args:
chdir: "{{ deploy_dir }}"
become_user: "{{ deploy_user }}"
register: container_logs
changed_when: false
- name: "[10/10] 📋 Affichage des logs"
debug:
var: container_logs.stdout_lines
# ====================================================================
# RÉSUMÉ FINAL
# ====================================================================
- name: "✅ Déploiement terminé avec succès!"
debug:
msg:
- "🎉 L'application DockeZR a été déployée avec succès!"
- ""
- "🌐 Accès aux services:"
- " - Frontend: http://{{ ansible_host }}:{{ frontend_port }}"
- " - Backend API: http://{{ ansible_host }}:{{ backend_port }}"
- " - Swagger: http://{{ ansible_host }}:{{ backend_port }}/docs"
- " - Prometheus: http://{{ ansible_host }}:{{ prometheus_port }}"
- " - Grafana: http://{{ ansible_host }}:{{ grafana_port }}"
- ""
- "📁 Répertoire de déploiement: {{ deploy_dir }}"
- ""
- "🔧 Commandes utiles:"
- " - Voir les logs: cd {{ deploy_dir }} && docker compose -f docker-compose.prod.yml logs -f"
- " - Redémarrer: cd {{ deploy_dir }} && docker compose -f docker-compose.prod.yml restart"
- " - Arrêter: cd {{ deploy_dir }} && docker compose -f docker-compose.prod.yml down"
+29
View File
@@ -0,0 +1,29 @@
# Variables globales pour tous les hôtes
---
# Configuration du projet
project_name: dockezr
project_repo: "https://github.com/VOTRE_USERNAME/dockezr.git"
project_branch: main
deploy_dir: "/opt/{{ project_name }}"
# Configuration Docker
docker_compose_version: "2.23.0"
# Utilisateur du système
deploy_user: "{{ ansible_user }}"
# Ports de l'application
backend_port: 8001
frontend_port: 3000
prometheus_port: 9090
grafana_port: 3001
# Configuration de la base de données (Production)
postgres_user: dockezr_user
postgres_password: "changez_ce_mot_de_passe_en_production"
postgres_db: dockezr
# Configuration Grafana
grafana_admin_user: admin
grafana_admin_password: "changez_ce_mot_de_passe_en_production"
+2
View File
@@ -0,0 +1,2 @@
[production]
141.253.118.141 ansible_user=root ansible_ssh_private_key_file=/ssh/ssh-key-2025-10-16.key ansible_python_interpreter=/usr/bin/python3 ansible_host_key_checking=false
+10
View File
@@ -0,0 +1,10 @@
# Inventaire Ansible pour test en LOCAL
# Utilisez ce fichier pour tester le playbook sur votre machine locale avant le déploiement distant
[local]
localhost ansible_connection=local ansible_python_interpreter=/usr/bin/python3
[local:vars]
# Variables spécifiques pour le test local
deploy_dir=/tmp/dockezr-test
+138
View File
@@ -0,0 +1,138 @@
# Script de pré-vérification avant déploiement
# Vérifie que tout est prêt pour le déploiement Ansible
Write-Host "╔══════════════════════════════════════════════════════╗" -ForegroundColor Cyan
Write-Host "║ Pré-vérification du Déploiement Ansible ║" -ForegroundColor Cyan
Write-Host "╚══════════════════════════════════════════════════════╝" -ForegroundColor Cyan
Write-Host ""
$allGood = $true
# 1. Vérifier WSL
Write-Host "[1/7] Vérification de WSL..." -ForegroundColor Yellow
try {
$wslCheck = wsl --list --verbose 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host " ✓ WSL installé" -ForegroundColor Green
} else {
Write-Host " ✗ WSL non installé" -ForegroundColor Red
Write-Host " Installer avec: wsl --install" -ForegroundColor Yellow
$allGood = $false
}
} catch {
Write-Host " ✗ WSL non disponible" -ForegroundColor Red
$allGood = $false
}
# 2. Vérifier Ansible
Write-Host "[2/7] Vérification d'Ansible..." -ForegroundColor Yellow
$ansibleCheck = wsl bash -c "which ansible" 2>&1
if ($LASTEXITCODE -eq 0) {
$version = wsl bash -c "ansible --version | head -n1"
Write-Host " ✓ Ansible installé: $version" -ForegroundColor Green
} else {
Write-Host " ✗ Ansible non installé dans WSL" -ForegroundColor Red
Write-Host " Installer avec: wsl bash -c 'sudo apt update && sudo apt install ansible -y'" -ForegroundColor Yellow
$allGood = $false
}
# 3. Vérifier les fichiers
Write-Host "[3/7] Vérification des fichiers..." -ForegroundColor Yellow
$files = @(
"deploy.yml",
"inventory.ini",
"group_vars\all.yml",
"templates\env.prod.j2",
"..\..\sskdockerz\ssh-key-2025-10-16.key"
)
foreach ($file in $files) {
if (Test-Path $file) {
Write-Host "$file" -ForegroundColor Green
} else {
Write-Host "$file manquant" -ForegroundColor Red
$allGood = $false
}
}
# 4. Vérifier la configuration de l'inventaire
Write-Host "[4/7] Vérification de l'inventaire..." -ForegroundColor Yellow
$inventoryContent = Get-Content "inventory.ini" -Raw
if ($inventoryContent -match "VOTRE_IP_SERVEUR") {
Write-Host " ⚠ L'inventaire n'est pas configuré (contient VOTRE_IP_SERVEUR)" -ForegroundColor Yellow
Write-Host " Éditez inventory.ini et remplacez les valeurs" -ForegroundColor Yellow
$allGood = $false
} else {
Write-Host " ✓ Inventaire configuré" -ForegroundColor Green
}
# 5. Vérifier la configuration des variables
Write-Host "[5/7] Vérification des variables..." -ForegroundColor Yellow
$varsContent = Get-Content "group_vars\all.yml" -Raw
if ($varsContent -match "VOTRE_USERNAME") {
Write-Host " ⚠ Les variables ne sont pas configurées (contient VOTRE_USERNAME)" -ForegroundColor Yellow
Write-Host " Éditez group_vars/all.yml et remplacez project_repo" -ForegroundColor Yellow
$allGood = $false
} else {
Write-Host " ✓ Variables configurées" -ForegroundColor Green
}
if ($varsContent -match "changez_ce_mot_de_passe") {
Write-Host " ⚠ Les mots de passe par défaut sont toujours présents" -ForegroundColor Yellow
Write-Host " Changez-les dans group_vars/all.yml pour la production" -ForegroundColor Yellow
}
# 6. Vérifier la syntaxe YAML
Write-Host "[6/7] Vérification de la syntaxe YAML..." -ForegroundColor Yellow
$wslPath = wsl wslpath -a "$PWD"
$syntaxCheck = wsl bash -c "cd '$wslPath' && ansible-playbook deploy.yml --syntax-check" 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host " ✓ Syntaxe du playbook valide" -ForegroundColor Green
} else {
Write-Host " ✗ Erreur de syntaxe dans le playbook" -ForegroundColor Red
Write-Host $syntaxCheck
$allGood = $false
}
# 7. Test de connexion (optionnel)
Write-Host "[7/7] Test de connexion SSH..." -ForegroundColor Yellow
if ($inventoryContent -notmatch "VOTRE_IP_SERVEUR") {
$pingResult = wsl bash -c "cd '$wslPath'; timeout 10 ansible all -i inventory.ini -m ping" 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host " ✓ Connexion SSH réussie!" -ForegroundColor Green
} else {
Write-Host " ✗ Impossible de se connecter au serveur" -ForegroundColor Red
Write-Host " Vérifiez l'IP, le user et la clé SSH" -ForegroundColor Yellow
$allGood = $false
}
} else {
Write-Host " - Test ignoré (inventaire non configuré)" -ForegroundColor Gray
}
# Résumé
Write-Host ""
Write-Host "═══════════════════════════════════════════════════════" -ForegroundColor Cyan
if ($allGood) {
Write-Host "✓ TOUTES LES VÉRIFICATIONS SONT PASSÉES!" -ForegroundColor Green
Write-Host ""
Write-Host "Vous êtes prêt à déployer!" -ForegroundColor Green
Write-Host ""
Write-Host "Lancez le déploiement avec:" -ForegroundColor Yellow
Write-Host " .\deploy-auto.ps1" -ForegroundColor White
Write-Host ""
Write-Host "Ou en mode test:" -ForegroundColor Yellow
Write-Host " .\deploy-auto.ps1 -TestMode" -ForegroundColor White
} else {
Write-Host "✗ CERTAINES VÉRIFICATIONS ONT ÉCHOUÉ" -ForegroundColor Red
Write-Host ""
Write-Host "Corrigez les problèmes ci-dessus avant de déployer." -ForegroundColor Yellow
Write-Host ""
Write-Host "Besoin d'aide ? Consultez:" -ForegroundColor Yellow
Write-Host " - QUICK_START.md" -ForegroundColor White
Write-Host " - GUIDE_EXECUTION.md" -ForegroundColor White
}
Write-Host "═══════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
+35
View File
@@ -0,0 +1,35 @@
# Fichier de configuration de production généré automatiquement par Ansible
# Date de génération: {{ ansible_date_time.iso8601 }}
# ==============================================
# Configuration Base de Données PostgreSQL
# ==============================================
POSTGRES_USER={{ postgres_user }}
POSTGRES_PASSWORD={{ postgres_password }}
POSTGRES_DB={{ postgres_db }}
DB_PORT=5432
# ==============================================
# Ports des Services
# ==============================================
BACKEND_PORT={{ backend_port }}
FRONTEND_PORT={{ frontend_port }}
PROMETHEUS_PORT={{ prometheus_port }}
GRAFANA_PORT={{ grafana_port }}
# ==============================================
# Configuration Frontend
# ==============================================
NEXT_PUBLIC_API_URL=http://{{ ansible_host }}:{{ backend_port }}
# ==============================================
# Configuration Grafana
# ==============================================
GRAFANA_USER={{ grafana_admin_user }}
GRAFANA_PASSWORD={{ grafana_admin_password }}
# ==============================================
# Configuration de Production
# ==============================================
NODE_ENV=production
+129
View File
@@ -0,0 +1,129 @@
# Script de pre-verification simplifie
param()
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host " Pre-verification du Deploiement Ansible" -ForegroundColor Cyan
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
$allGood = $true
# 1. Verifier WSL
Write-Host "[1/6] Verification de WSL..." -ForegroundColor Yellow
try {
$wslCheck = wsl --list --verbose 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host " OK - WSL installe" -ForegroundColor Green
} else {
Write-Host " ERREUR - WSL non installe" -ForegroundColor Red
$allGood = $false
}
} catch {
Write-Host " ERREUR - WSL non disponible" -ForegroundColor Red
$allGood = $false
}
# 2. Verifier Ansible
Write-Host "[2/6] Verification d'Ansible..." -ForegroundColor Yellow
$ansibleCheck = wsl bash -c "which ansible" 2>&1
if ($LASTEXITCODE -eq 0) {
$version = wsl bash -c "ansible --version | head -n1"
Write-Host " OK - Ansible installe: $version" -ForegroundColor Green
} else {
Write-Host " ERREUR - Ansible non installe dans WSL" -ForegroundColor Red
Write-Host " Commande: wsl bash -c 'sudo apt update && sudo apt install ansible -y'" -ForegroundColor Yellow
$allGood = $false
}
# 3. Verifier les fichiers
Write-Host "[3/6] Verification des fichiers..." -ForegroundColor Yellow
$filesMissing = $false
if (Test-Path "deploy.yml") {
Write-Host " OK - deploy.yml" -ForegroundColor Green
} else {
Write-Host " ERREUR - deploy.yml manquant" -ForegroundColor Red
$filesMissing = $true
}
if (Test-Path "inventory.ini") {
Write-Host " OK - inventory.ini" -ForegroundColor Green
} else {
Write-Host " ERREUR - inventory.ini manquant" -ForegroundColor Red
$filesMissing = $true
}
if (Test-Path "group_vars\all.yml") {
Write-Host " OK - group_vars\all.yml" -ForegroundColor Green
} else {
Write-Host " ERREUR - group_vars\all.yml manquant" -ForegroundColor Red
$filesMissing = $true
}
if (Test-Path "..\..\sskdockerz\ssh-key-2025-10-16.key") {
Write-Host " OK - cle SSH trouvee" -ForegroundColor Green
} else {
Write-Host " ERREUR - cle SSH manquante" -ForegroundColor Red
$filesMissing = $true
}
if ($filesMissing) {
$allGood = $false
}
# 4. Verifier l'inventaire
Write-Host "[4/6] Verification de l'inventaire..." -ForegroundColor Yellow
$inventoryContent = Get-Content "inventory.ini" -Raw
if ($inventoryContent -match "VOTRE_IP_SERVEUR") {
Write-Host " ATTENTION - L'inventaire n'est pas configure" -ForegroundColor Yellow
Write-Host " Editez inventory.ini et remplacez les valeurs" -ForegroundColor Yellow
$allGood = $false
} else {
Write-Host " OK - Inventaire configure" -ForegroundColor Green
}
# 5. Verifier les variables
Write-Host "[5/6] Verification des variables..." -ForegroundColor Yellow
$varsContent = Get-Content "group_vars\all.yml" -Raw
if ($varsContent -match "VOTRE_USERNAME") {
Write-Host " ATTENTION - Variables non configurees" -ForegroundColor Yellow
Write-Host " Editez group_vars/all.yml" -ForegroundColor Yellow
$allGood = $false
} else {
Write-Host " OK - Variables configurees" -ForegroundColor Green
}
# 6. Test de syntaxe
Write-Host "[6/6] Verification de la syntaxe YAML..." -ForegroundColor Yellow
$wslPath = wsl wslpath -a "$PWD"
$syntaxCheck = wsl bash -c "cd '$wslPath'; ansible-playbook deploy.yml --syntax-check" 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host " OK - Syntaxe du playbook valide" -ForegroundColor Green
} else {
Write-Host " ERREUR - Erreur de syntaxe dans le playbook" -ForegroundColor Red
Write-Host $syntaxCheck
$allGood = $false
}
# Resultat
Write-Host ""
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
if ($allGood) {
Write-Host " TOUTES LES VERIFICATIONS SONT PASSEES!" -ForegroundColor Green
Write-Host ""
Write-Host "Vous etes pret a deployer!" -ForegroundColor Green
Write-Host ""
Write-Host "Pour deployer avec configuration interactive:" -ForegroundColor Yellow
Write-Host " .\deploy-interactive.ps1" -ForegroundColor White
Write-Host ""
} else {
Write-Host " CERTAINES VERIFICATIONS ONT ECHOUE" -ForegroundColor Red
Write-Host ""
Write-Host "Corrigez les problemes ci-dessus avant de deployer." -ForegroundColor Yellow
Write-Host ""
}
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
+19
View File
@@ -0,0 +1,19 @@
# Verifier les conteneurs sur le serveur
$ServerIP = "141.253.118.141"
Write-Host "`n════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host " VERIFICATION DES CONTENEURS SUR LE SERVEUR" -ForegroundColor Cyan
Write-Host "════════════════════════════════════════════════════`n" -ForegroundColor Cyan
docker run --rm -v "${PWD}\..\sskdockerz:/ssh" willhallonline/ansible:latest sh -c 'chmod 600 /ssh/ssh-key-2025-10-16.key && ssh -o StrictHostKeyChecking=no -i /ssh/ssh-key-2025-10-16.key root@141.253.118.141 "docker ps"'
Write-Host "`n════════════════════════════════════════════════════`n" -ForegroundColor Cyan
Write-Host "Vos services sont accessibles a:`n" -ForegroundColor Green
Write-Host " Frontend: http://$ServerIP`:3000" -ForegroundColor White
Write-Host " Backend API: http://$ServerIP`:8001" -ForegroundColor White
Write-Host " Swagger: http://$ServerIP`:8001/docs" -ForegroundColor White
Write-Host " Prometheus: http://$ServerIP`:9090" -ForegroundColor White
Write-Host " Grafana: http://$ServerIP`:3001`n" -ForegroundColor White
+98
View File
@@ -0,0 +1,98 @@
# Script de deploiement complet sur le serveur
$ServerIP = "141.253.118.141"
$ServerUser = "root"
$KeyPath = "..\sskdockerz\ssh-key-2025-10-16.key"
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host " DEPLOIEMENT COMPLET DOCKEZR" -ForegroundColor Cyan
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
Write-Host "Serveur: $ServerIP" -ForegroundColor White
Write-Host ""
Write-Host "[1/5] Copie des fichiers du projet..." -ForegroundColor Cyan
# Utiliser scp pour copier les fichiers
docker run --rm `
-v "${PWD}:/project" `
-v "${PWD}\..\sskdockerz:/ssh" `
-w /project `
willhallonline/ansible:latest `
sh -c "chmod 600 /ssh/ssh-key-2025-10-16.key && scp -o StrictHostKeyChecking=no -i /ssh/ssh-key-2025-10-16.key -r /project root@141.253.118.141:/opt/dockezr"
if ($LASTEXITCODE -eq 0) {
Write-Host " OK - Fichiers copies" -ForegroundColor Green
} else {
Write-Host " Erreur lors de la copie" -ForegroundColor Red
}
Write-Host "[2/5] Verification des fichiers sur le serveur..." -ForegroundColor Cyan
docker run --rm `
-v "${PWD}\..\sskdockerz:/ssh" `
willhallonline/ansible:latest `
sh -c "chmod 600 /ssh/ssh-key-2025-10-16.key && ssh -o StrictHostKeyChecking=no -i /ssh/ssh-key-2025-10-16.key root@141.253.118.141 'ls -la /opt/dockezr/'"
Write-Host "[3/5] Configuration de l'environnement..." -ForegroundColor Cyan
docker run --rm `
-v "${PWD}\..\sskdockerz:/ssh" `
willhallonline/ansible:latest `
sh -c @"
chmod 600 /ssh/ssh-key-2025-10-16.key && ssh -o StrictHostKeyChecking=no -i /ssh/ssh-key-2025-10-16.key root@141.253.118.141 'cat > /opt/dockezr/.env << EOF
DATABASE_URL=postgresql://user:password@db:5432/dockezr
POSTGRES_USER=user
POSTGRES_PASSWORD=password
POSTGRES_DB=dockezr
NEXT_PUBLIC_API_URL=http://141.253.118.141:8001
EOF'
"@
Write-Host " OK - Environnement configure" -ForegroundColor Green
Write-Host "[4/5] Lancement de docker-compose..." -ForegroundColor Cyan
Write-Host " Cela peut prendre 2-3 minutes..." -ForegroundColor Yellow
docker run --rm `
-v "${PWD}\..\sskdockerz:/ssh" `
willhallonline/ansible:latest `
sh -c "chmod 600 /ssh/ssh-key-2025-10-16.key && ssh -o StrictHostKeyChecking=no -i /ssh/ssh-key-2025-10-16.key root@141.253.118.141 'cd /opt/dockezr && docker-compose up -d'"
if ($LASTEXITCODE -eq 0) {
Write-Host " OK - Conteneurs lances" -ForegroundColor Green
} else {
Write-Host " Erreur lors du lancement" -ForegroundColor Red
}
Write-Host ""
Write-Host "[5/5] Verification des conteneurs..." -ForegroundColor Cyan
Write-Host ""
Start-Sleep -Seconds 5
docker run --rm `
-v "${PWD}\..\sskdockerz:/ssh" `
willhallonline/ansible:latest `
sh -c "chmod 600 /ssh/ssh-key-2025-10-16.key && ssh -o StrictHostKeyChecking=no -i /ssh/ssh-key-2025-10-16.key root@141.253.118.141 'docker ps'"
Write-Host ""
if ($LASTEXITCODE -eq 0) {
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host " DEPLOIEMENT TERMINE!" -ForegroundColor Green
Write-Host "════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host ""
Write-Host "Acces aux services:" -ForegroundColor Cyan
Write-Host ""
Write-Host " Frontend: http://$ServerIP`:3000" -ForegroundColor White
Write-Host " Backend API: http://$ServerIP`:8001" -ForegroundColor White
Write-Host " Swagger: http://$ServerIP`:8001/docs" -ForegroundColor White
Write-Host " Prometheus: http://$ServerIP`:9090" -ForegroundColor White
Write-Host " Grafana: http://$ServerIP`:3001" -ForegroundColor White
Write-Host ""
Write-Host "Les services vont demarrer dans 30-60 secondes..." -ForegroundColor Yellow
Write-Host ""
Write-Host "Ouverture du frontend dans le navigateur..." -ForegroundColor Cyan
Start-Sleep -Seconds 3
Start-Process "http://$ServerIP`:3000"
}
+72
View File
@@ -0,0 +1,72 @@
# Deploiement immediat sur le serveur
$ServerIP = "141.253.118.141"
Write-Host "`n════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host " DEPLOIEMENT DOCKEZR SUR LE SERVEUR" -ForegroundColor Cyan
Write-Host "════════════════════════════════════════════════════`n" -ForegroundColor Cyan
Write-Host "Serveur: $ServerIP`n" -ForegroundColor White
# Etape 1: Copie des fichiers
Write-Host "[1/3] Copie des fichiers sur le serveur..." -ForegroundColor Yellow
Write-Host "Cela peut prendre 1-2 minutes...`n" -ForegroundColor Gray
docker run --rm `
-v "${PWD}:/project" `
-v "${PWD}\..\sskdockerz:/ssh" `
-w / `
willhallonline/ansible:latest `
sh -c "chmod 600 /ssh/ssh-key-2025-10-16.key && tar czf - -C /project . | ssh -o StrictHostKeyChecking=no -i /ssh/ssh-key-2025-10-16.key root@$ServerIP 'mkdir -p /opt/dockezr && cd /opt/dockezr && tar xzf -'"
if ($LASTEXITCODE -eq 0) {
Write-Host "OK - Fichiers copies`n" -ForegroundColor Green
} else {
Write-Host "ERREUR lors de la copie`n" -ForegroundColor Red
exit 1
}
# Etape 2: Lancement de docker-compose
Write-Host "[2/3] Lancement de docker-compose..." -ForegroundColor Yellow
Write-Host "Construction et demarrage des conteneurs...`n" -ForegroundColor Gray
docker run --rm `
-v "${PWD}\..\sskdockerz:/ssh" `
willhallonline/ansible:latest `
sh -c "chmod 600 /ssh/ssh-key-2025-10-16.key && ssh -o StrictHostKeyChecking=no -i /ssh/ssh-key-2025-10-16.key root@$ServerIP 'cd /opt/dockezr && docker-compose up -d --build'"
if ($LASTEXITCODE -eq 0) {
Write-Host "OK - Conteneurs lances`n" -ForegroundColor Green
} else {
Write-Host "ERREUR lors du lancement`n" -ForegroundColor Red
}
# Etape 3: Verification
Write-Host "[3/3] Verification des conteneurs en cours...`n" -ForegroundColor Yellow
Start-Sleep -Seconds 5
docker run --rm `
-v "${PWD}\..\sskdockerz:/ssh" `
willhallonline/ansible:latest `
sh -c "chmod 600 /ssh/ssh-key-2025-10-16.key && ssh -o StrictHostKeyChecking=no -i /ssh/ssh-key-2025-10-16.key root@$ServerIP 'docker ps --format \"table {{.Names}}\t{{.Status}}\t{{.Ports}}\"'"
Write-Host "`n════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host " DEPLOIEMENT TERMINE!" -ForegroundColor Green
Write-Host "════════════════════════════════════════════════════`n" -ForegroundColor Green
Write-Host "Vos services sont accessibles a:`n" -ForegroundColor Cyan
Write-Host " Frontend: http://$ServerIP`:3000" -ForegroundColor White
Write-Host " Backend API: http://$ServerIP`:8001" -ForegroundColor White
Write-Host " Swagger: http://$ServerIP`:8001/docs" -ForegroundColor White
Write-Host " Prometheus: http://$ServerIP`:9090" -ForegroundColor White
Write-Host " Grafana: http://$ServerIP`:3001`n" -ForegroundColor White
Write-Host "Attendez 30-60 secondes que tout demarre completement...`n" -ForegroundColor Yellow
Write-Host "Ouverture du frontend..." -ForegroundColor Cyan
Start-Sleep -Seconds 3
Start-Process "http://$ServerIP`:3000"
Write-Host "`nDeploiement termine! Les conteneurs sont en cours de demarrage." -ForegroundColor Green
+35
View File
@@ -0,0 +1,35 @@
# Script pour ouvrir les ports du pare-feu sur la VM Oracle
$ServerIP = "141.253.118.141"
Write-Host "`n════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host " OUVERTURE DES PORTS DU PARE-FEU" -ForegroundColor Cyan
Write-Host "════════════════════════════════════════════════════`n" -ForegroundColor Cyan
Write-Host "Configuration du pare-feu sur le serveur...`n" -ForegroundColor Yellow
docker run --rm -v "${PWD}\..\sskdockerz:/ssh" willhallonline/ansible:latest sh -c 'chmod 600 /ssh/ssh-key-2025-10-16.key; ssh -o StrictHostKeyChecking=no -i /ssh/ssh-key-2025-10-16.key root@141.253.118.141 "iptables -I INPUT 6 -m state --state NEW -p tcp --dport 3000 -j ACCEPT && iptables -I INPUT 6 -m state --state NEW -p tcp --dport 8001 -j ACCEPT && iptables -I INPUT 6 -m state --state NEW -p tcp --dport 9090 -j ACCEPT && iptables -I INPUT 6 -m state --state NEW -p tcp --dport 3001 -j ACCEPT && netfilter-persistent save"'
if ($LASTEXITCODE -eq 0) {
Write-Host "`nOK - Ports ouverts dans le pare-feu de la VM`n" -ForegroundColor Green
} else {
Write-Host "`nERREUR - Probleme avec le pare-feu`n" -ForegroundColor Red
}
Write-Host "════════════════════════════════════════════════════`n" -ForegroundColor Cyan
Write-Host "Ports ouverts:" -ForegroundColor Green
Write-Host " - 3000 (Frontend)" -ForegroundColor White
Write-Host " - 8001 (Backend API)" -ForegroundColor White
Write-Host " - 9090 (Prometheus)" -ForegroundColor White
Write-Host " - 3001 (Grafana)`n" -ForegroundColor White
Write-Host "IMPORTANT:" -ForegroundColor Yellow
Write-Host "Vous devez AUSSI ouvrir ces ports dans Oracle Cloud:" -ForegroundColor Yellow
Write-Host " 1. Allez sur cloud.oracle.com" -ForegroundColor White
Write-Host " 2. Compute > Instances > Votre VM" -ForegroundColor White
Write-Host " 3. Subnet > Security List" -ForegroundColor White
Write-Host " 4. Add Ingress Rules pour les ports 3000, 8001, 9090, 3001`n" -ForegroundColor White
Write-Host "Apres avoir ouvert les ports Oracle Cloud, testez:" -ForegroundColor Cyan
Write-Host " http://$ServerIP`:3000`n" -ForegroundColor White