Aller au contenu
TAAF-OPS --:-- UTC

Vagrant - Infrastructure Locale

Pour éviter les limitations de Docker Desktop et garantir une isolation totale, nous utilisons des VMs pilotées par Vagrant. Deux providers selon le contexte :

ProviderUsageAvantage
VMware DesktopVM de développement (WSL → VMware)Performances I/O, stabilité
VirtualBoxVMs de formation (monitoring + SIEM)Gratuit, multi-plateforme

graph TB
 subgraph HOST["Machine Hôte (Windows)"]
 subgraph WSL["WSL2"]
 VAGRANT[Vagrant CLI]
 MKCERT[mkcert]
 GIT[Git]
 end

 subgraph VMWARE["VMware Workstation"]
 subgraph VM["Ubuntu 22.04 VM
192.168.56.10"] DOCKER[Docker] SERVICES[Services] end end end VAGRANT -->|"vagrant up"|VM DOCKER --> SERVICES style HOST fill:#1a1a2e,stroke:#16213e,color:#fff style WSL fill:#0f3460,stroke:#16213e,color:#fff style VMWARE fill:#533483,stroke:#16213e,color:#fff style VM fill:#e94560,stroke:#16213e,color:#fff

OutilVersionInstallation
VMware Workstation17+vmware.com
Vagrant2.4+vagrantup.com
Vagrant VMware PluginLatestvagrant plugin install vagrant-vmware-desktop
VMware UtilityLatestvagrant-vmware-utility

Vagrant est installé sur Windows mais piloté depuis WSL. Ajoutez dans ~/.bashrc :

Fenêtre de terminal
export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"
export PATH="$PATH:/mnt/c/Program Files/Vagrant/bin"
alias vagrant='"/mnt/c/Program Files/Vagrant/bin/vagrant.exe"'
Fenêtre de terminal
source ~/.bashrc
vagrant --version

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-22.04"
config.vm.provider "vmware_desktop" do |v|
v.gui = false
v.allowlist_verified = true
v.vmx["memsize"] = "4096"
v.vmx["numvcpus"] = "2"
v.vmx["displayName"] = "KDS-Dev-Local"
end
config.vm.network "private_network", ip: "192.168.56.10"
config.vm.hostname = "kds-dev-local"
config.vm.provision "shell", inline: <<-SHELL
export DEBIAN_FRONTEND=noninteractive
apt-get update && apt-get upgrade -y
apt-get install -y curl git apt-transport-https ca-certificates \
software-properties-common gnupg lsb-release
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
usermod -aG docker vagrant
rm get-docker.sh
systemctl enable docker && systemctl start docker
SHELL
end

Pour un environnement complet avec Dokploy et DNS local, voir Dokploy.


Configuration multi-VM pour la formation : monitoring + SIEM, provisionnées automatiquement via les scripts du repo server.

Fenêtre de terminal
# Debian/Ubuntu
sudo apt install virtualbox vagrant
# macOS
brew install virtualbox vagrant
Vagrant.configure("2") do |config|
config.vm.box = "debian/bookworm64"
config.vm.box_check_update = true
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
vb.cpus = 2
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
# VM 1 - Monitoring
config.vm.define "monitoring" do |monitoring|
monitoring.vm.hostname = "kds-monitoring"
monitoring.vm.network "private_network", ip: "192.168.56.10"
monitoring.vm.provider "virtualbox" do |vb|
vb.name = "KDS-Monitoring"
end
monitoring.vm.provision "shell", inline: <<-SHELL
apt-get update && apt-get install -y cloud-init git
git clone https://git.kodetis.io/kds-formation/server.git /tmp/server
cd /tmp/server
sudo bash initialization/setup_initial_server.sh <<EOF
tech-taaf
EOF
sudo bash initialization/tools-install.sh
sudo ./zsh/01_install_zsh_omzsh.sh <<EOF
tech-taaf
EOF
sudo ./zsh/02_install_zsh_tools.sh
sudo -u tech-taaf cp /tmp/server/zsh/03_.zshrc /home/tech-taaf/.zshrc
sudo -u tech-taaf cp /tmp/server/zsh/04_.p10k.zsh /home/tech-taaf/.p10k.zsh
rm -rf /tmp/server
SHELL
end
# VM 2 - SIEM (plus de RAM)
config.vm.define "siem" do |siem|
siem.vm.hostname = "kds-siem"
siem.vm.network "private_network", ip: "192.168.56.11"
siem.vm.provider "virtualbox" do |vb|
vb.name = "KDS-SIEM"
vb.memory = "4096"
end
siem.vm.provision "shell", inline: <<-SHELL
apt-get update && apt-get install -y cloud-init git
git clone https://git.kodetis.io/kds-formation/server.git /tmp/server
cd /tmp/server
sudo bash initialization/setup_initial_server.sh <<EOF
tech-taaf
EOF
sudo bash initialization/tools-install.sh
sudo ./zsh/01_install_zsh_omzsh.sh <<EOF
tech-taaf
EOF
sudo ./zsh/02_install_zsh_tools.sh
sudo -u tech-taaf cp /tmp/server/zsh/03_.zshrc /home/tech-taaf/.zshrc
sudo -u tech-taaf cp /tmp/server/zsh/04_.p10k.zsh /home/tech-taaf/.p10k.zsh
rm -rf /tmp/server
SHELL
end
end

Pour un provisioning déclaratif, créez un fichier cloud-init.yml :

#cloud-config
users:
- name: tech-taaf
groups: sudo, docker
shell: /bin/zsh
sudo: ALL=(ALL) NOPASSWD:ALL
package_update: true
packages: [git, curl, wget, zsh, ca-certificates, gnupg]
timezone: Indian/Reunion
runcmd:
- curl -fsSL https://get.docker.com | sh
- usermod -aG docker tech-taaf
- git clone https://git.kodetis.io/kds-formation/server.git /tmp/server
- sudo -u tech-taaf bash /tmp/server/zsh/01_install_zsh_omzsh.sh
- sudo -u tech-taaf bash /tmp/server/zsh/02_install_zsh_tools.sh
- rm -rf /tmp/server
# Dans le Vagrantfile
config.vm.provision "shell", inline: <<-SHELL
cloud-init --file /vagrant/cloud-init.yml single --name all
SHELL

Fenêtre de terminal
# Cycle de vie
vagrant up # Créer et démarrer
vagrant ssh # Connexion SSH
vagrant halt # Arrêter
vagrant reload # Redémarrer
vagrant destroy -f # Supprimer
# Provisioning
vagrant provision # Re-exécuter le provisioning
vagrant reload --provision
# Multi-VM
vagrant up monitoring # VM spécifique
vagrant ssh siem # SSH vers une VM
# Debug
vagrant status
vagrant global-status
vagrant up --debug 2>&1 | tee vagrant.log

Fenêtre de terminal
vagrant plugin list
vagrant plugin uninstall vagrant-vmware-desktop
vagrant plugin install vagrant-vmware-desktop
# Vérifier aussi le service VMware Utility dans services.msc
Fenêtre de terminal
VBoxManage list hostonlyifs
# Si vide :
VBoxManage hostonlyif create
Fenêtre de terminal
# Dans /etc/wsl.conf :
[automount]
options = "metadata"

Voir aussi :