Référence rapide

Antisèche Vagrantfile

Guide de référence rapide pour la configuration de Vagrantfile : paramètres de box, redirection de ports, réseaux privés/publics, dossiers synchronisés et provisionneurs.

· Publié le

Vagrant Vagrant crée et gère des environnements de développement de machines virtuelles via un fichier de configuration unique nommé Vagrantfile.

Configuration du Vagrantfile

Vagrant.configure("2") do |config|
  # Base box image
  config.vm.box = "ubuntu/focal64"

  # Optional URL if box does not exist locally
  # config.vm.box_url = "https://vagrantcloud.com/ubuntu/boxes/focal64"

  # Port Forwarding: access host localhost:8080 to guest 80
  config.vm.network "forwarded_port", guest: 80, host: 8080

  # Private Network: host-only access via static IP
  config.vm.network "private_network", ip: "192.168.33.10"

  # Public Network: bridged directly to local physical network
  # config.vm.network "public_network"

  # SSH Agent Forwarding
  # config.ssh.forward_agent = true

  # Synced Folders: mount host directory to guest path
  config.vm.synced_folder "../data", "/vagrant_data"

  # Provider customization (e.g. VirtualBox)
  config.vm.provider "virtualbox" do |vb|
    vb.gui = false
    vb.memory = "2048"
    vb.cpus = 2
  end

  # Shell Provisioning
  config.vm.provision "shell", inline: <<-SHELL
    apt-get update
    apt-get install -y nginx
  SHELL

  # Puppet Provisioning
  # config.vm.provision :puppet do |puppet|
  #   puppet.manifests_path = "manifests"
  #   puppet.manifest_file  = "site.pp"
  # end

  # Chef Solo Provisioning
  # config.vm.provision :chef_solo do |chef|
  #   chef.cookbooks_path = "../cookbooks"
  #   chef.add_recipe "nginx"
  # end
end

Références

Sujets associés