# Vagrant

# Vagrantfile - examples

Fichier basique juste pour lancer une VM sur VirtualBox

```ruby
Vagrant.configure("2") do |config|
  config.vm.box = "debian/bullseye64"

    config.vm.define Debian-Lab do |cfg|
	  cfg.vm.hostname = "Debian-Lab"
      cfg.vm.provider "virtualbox" do |v|
        v.name= "Debian-Lab"
      end #end VB
   end #end cfg
end 
```

Installation 3 VM avec Docker sur Virtual Box et Debian 11

```ruby
Vagrant.configure("2") do |config|
  config.vm.box = "debian/bullseye64"
  common = <<-SHELL
  sudo apt update 2>&1 >/dev/null
  sudo apt install  tree git vim curl -y 2>&1 >/dev/null
  SHELL

  NODES = [
  	{ :hostname => "docker1", :ip => "192.168.12.78", :cpus => 4, :mem => 2048},
  	 { :hostname => "docker2", :ip => "192.168.12.79", :cpus => 4 , :mem => 2048},
	]
  NODES.each do |node|
    config.vm.define node[:hostname] do |cfg|
      cfg.vm.network "private_network", ip: node[:ip]
      cfg.vm.hostname = node[:hostname]
      cfg.vm.provider "virtualbox" do |v|
        v.name= node[:hostname]
        v.memory= node[:mem]
        v.cpus= node[:cpus]
      end #end VB
      #lancement commande SHELL pour le provissionning de la VM
       cfg.vm.provision "shell", inline: common
      #provissionning avec un script SHEEL
       cfg.vm.provision "shell", path:"docker_install.sh"
    end #end cfg
  end #end nodes
end 
```

#### Ressources Vagrant:

[→ Docs Officielle](https://developer.hashicorp.com/vagrant/docs/vagrantfile)  
[→ Stéphane Robert - Apprendre et Maitriser Vagrant](https://blog.stephane-robert.info/post/introduction-vagrant/)  
[→ Premiers pas avec Vagrant](https://j.hommet.net/initiation-vagrant/)

# Commandes de Base

*Commandes de base de Vagrant*

Lancement initiale VM, avec configuration rentrée dans le Vagrantfile:

```
vagrant up
```

Par défaut, si aucun nom de machine n'est précisé, ça sera le nom du dossier parent du Vagrantfile, suivi d'un id unique, qui sera utilisé.

Détruire les VM (spécifiées dans le fichier Vagrantfile)

```
vagrant destroy
```