Déployer la Voting App sur la VM locale#

Après avoir ouvert le dossier, lisez l’explication du rôle. La première commande de déploiement se trouve sous le titre Lancer le déploiement.

Ouvrez le bon dossier avant la première commande.

Windows, Ubuntu WSL#

Copiez cette commande entière :

cd "$(find /mnt/c/Users -maxdepth 6 -type d -path '*/Documents/tp-ansible-voting-app/ansible' -print -quit 2>/dev/null)"

macOS, Terminal#

cd ~/Documents/tp-ansible-voting-app/ansible

Le rôle voting_app clone l’application dans /opt/example-voting-app, puis utilise Docker Compose pour construire et démarrer vote, result, worker, redis et db.

Lancer le déploiement#

Terminal : Ubuntu WSL sous Windows ou Terminal macOS
Dossier : ansible
ansible-playbook -i inventories/local.yml site.yml --tags voting_app

Le premier build peut durer plusieurs minutes. Attendez le PLAY RECAP. Il doit afficher unreachable=0 et failed=0.

Vérifier les conteneurs#

ansible all -i inventories/local.yml -b -m ansible.builtin.command -a "docker compose -f /opt/example-voting-app/docker-compose.yml ps"

Les services doivent être démarrés.

Ouvrir l’application#

Interface de vote : http://localhost:8080

Résultats : http://localhost:8081

Envoyez au moins un vote. Attendez quelques secondes, puis vérifiez la page des résultats.

Vérifier depuis la VM#

Ouvrez un deuxième terminal.

Windows, PowerShell normal#

cd $HOME/Documents/tp-ansible-voting-app/infra/local
vagrant ssh

macOS, Terminal#

cd ~/Documents/tp-ansible-voting-app/infra/local
vagrant ssh

Dans le shell qui commence par vagrant@voting-app, testez l’interface de vote :

curl --fail http://127.0.0.1:8080

Testez les résultats :

curl --fail http://127.0.0.1:8081

Quittez la VM :

exit