Vagrant

De Linuxmemo.

(Différences entre les versions)
(Networking)
(Les "Boxes")
 
(22 versions intermédiaires masquées)
Ligne 1 : Ligne 1 :
[[Catégorie:Linux sysadmin]]
[[Catégorie:Linux sysadmin]]
 +
https://www.vagrantup.com/docs/getting-started/
==Install==
==Install==
https://www.vagrantup.com/downloads.html
https://www.vagrantup.com/downloads.html
==Nouveau projet (vide)==
==Nouveau projet (vide)==
 +
'''/!\ Attention /!\: Tout les VM sont gérées depuis leur répertoire respectif. Alors attention de bien vous placer a l’intérieur du répertoire de la VM.
 +
'''
  mkdir vagrant_getting_started
  mkdir vagrant_getting_started
  cd vagrant_getting_started
  cd vagrant_getting_started
  vagrant init
  vagrant init
  vim Vagrantfile
  vim Vagrantfile
 +
==Les "Boxes"==
==Les "Boxes"==
 +
*rechercher une box (depuis le site web uniquement)
 +
<s>https://atlas.hashicorp.com/boxes/search</s>
 +
https://app.vagrantup.com/boxes/search
*ajouter une box
*ajouter une box
  vagrant box add hashicorp/precise64
  vagrant box add hashicorp/precise64
Ligne 18 : Ligne 25 :
*deinstaller une box
*deinstaller une box
  vagrant box remove
  vagrant box remove
 +
*lister les box installées
 +
vagrant box list
 +
==synced folders (/vagrant)==
==synced folders (/vagrant)==
By default, Vagrant shares your project directory (remember, that is the one with the Vagrantfile) to the /vagrant directory in your guest machine.
By default, Vagrant shares your project directory (remember, that is the one with the Vagrantfile) to the /vagrant directory in your guest machine.
Ligne 25 : Ligne 35 :
  Vagrantfile
  Vagrantfile
==Provisioning==
==Provisioning==
 +
*shell scripts
in the same directory as your Vagrantfile:
in the same directory as your Vagrantfile:
  vim bootstrap.sh
  vim bootstrap.sh
Ligne 45 : Ligne 56 :
  or
  or
  vagrant reload --provision
  vagrant reload --provision
 +
*Chef
 +
*Puppet
 +
By default, Vagrant expects manifests to be in the manifests folder, and will run the default.pp manifest in that folder to kick off the Puppet run.
 +
 +
*déactiver le "provisionning"
 +
vagrant up --no-provision
 +
==Networking==
==Networking==
Let us setup a forwarded port so we can access Apache in our guest:
Let us setup a forwarded port so we can access Apache in our guest:
Ligne 57 : Ligne 75 :
  vagrant up
  vagrant up
Vagrant also has other forms of networking, allowing you to assign a static IP address to the guest machine, or to bridge the guest machine onto an existing network. If you are interested in other options, read the networking page.
Vagrant also has other forms of networking, allowing you to assign a static IP address to the guest machine, or to bridge the guest machine onto an existing network. If you are interested in other options, read the networking page.
 +
==Vagrant Share (with the world)==
 +
Créer un compte gratuit sur https://www.vagrantup.com/docs/other/atlas.html
 +
vagrant login
 +
vagrant share
 +
==Stop VM==
 +
With Vagrant, you suspend, halt, or destroy the guest machine.
 +
vagrant suspend
 +
or
 +
vagrant halt
 +
or
 +
vagrant destroy (Again, when you are ready to work again, just issue a vagrant up. The benefit of this is that no cruft is left on your machine.)
 +
==Liste de VM et status==
 +
vagrant status
 +
or
 +
vagrant status vmname
 +
==Plugins (usually RubyGems)==
 +
vagrant plugin list
 +
vagrant plugin install <name>...
 +
vagrant plugin update
 +
vagrant plugin update [<name>]
 +
vagrant plugin license <name> <license-file>
 +
vagrant plugin uninstall <name> [<name2> <name3> ...]
 +
==snapshot==
 +
vagrant snapshot
 +
vagrant snapshot push
 +
vagrant snapshot pop
 +
vagrant snapshot save
 +
vagrant snapshot restore
 +
vagrant snapshot list
 +
vagrant snapshot delete
 +
==Astuces==
 +
*Proxy pour box
 +
Définir les varialbes d'env:
 +
http_proxy=http://yourproxy:8080
 +
https_proxy=http://yourproxy:8080
 +
no_proxy=localhost,127.0.0.1
 +
 +
*proxy dans VM
 +
Install proxyconf:
 +
vagrant plugin install vagrant-proxyconf
 +
 +
Configure your Vagrantfile:
 +
config.proxy.http    = "http://yourproxy:8080"
 +
config.proxy.https    = "http://yourproxy:8080"
 +
config.proxy.no_proxy = "localhost,127.0.0.1"

Version actuelle en date du 8 juin 2020 à 14:19

https://www.vagrantup.com/docs/getting-started/

Sommaire

[modifier] Install

https://www.vagrantup.com/downloads.html

[modifier] Nouveau projet (vide)

/!\ Attention /!\: Tout les VM sont gérées depuis leur répertoire respectif. Alors attention de bien vous placer a l’intérieur du répertoire de la VM.

mkdir vagrant_getting_started
cd vagrant_getting_started
vagrant init
vim Vagrantfile

[modifier] Les "Boxes"

  • rechercher une box (depuis le site web uniquement)

https://atlas.hashicorp.com/boxes/search https://app.vagrantup.com/boxes/search

  • ajouter une box
vagrant box add hashicorp/precise64
(vagrant box add user/namebox)
  • démarrer la box
vagrant up
vagrant ssh
  • détruire l'instance d'une box
vagrant destroy
  • deinstaller une box
vagrant box remove
  • lister les box installées
vagrant box list

[modifier] synced folders (/vagrant)

By default, Vagrant shares your project directory (remember, that is the one with the Vagrantfile) to the /vagrant directory in your guest machine.

vagrant up
vagrant ssh
vagrant@precise64:~$ ls /vagrant
Vagrantfile

[modifier] Provisioning

  • shell scripts

in the same directory as your Vagrantfile:

vim bootstrap.sh

#!/usr/bin/env bash
apt-get update
apt-get install -y apache2
if ! [ -L /var/www ]; then
  rm -rf /var/www
  ln -fs /vagrant /var/www
fi
vim vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise64"
  config.vm.provision :shell, path: "bootstrap.sh"
end
vagrant up
or
vagrant reload --provision
  • Chef
  • Puppet

By default, Vagrant expects manifests to be in the manifests folder, and will run the default.pp manifest in that folder to kick off the Puppet run.

  • déactiver le "provisionning"

vagrant up --no-provision

[modifier] Networking

Let us setup a forwarded port so we can access Apache in our guest:

vim Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise64"
  config.vm.provision :shell, path: "bootstrap.sh"
  config.vm.network :forwarded_port, guest: 80, host: 4567
end
vagrant reload
or
vagrant up

Vagrant also has other forms of networking, allowing you to assign a static IP address to the guest machine, or to bridge the guest machine onto an existing network. If you are interested in other options, read the networking page.

[modifier] Vagrant Share (with the world)

Créer un compte gratuit sur https://www.vagrantup.com/docs/other/atlas.html

vagrant login
vagrant share

[modifier] Stop VM

With Vagrant, you suspend, halt, or destroy the guest machine.

vagrant suspend
or
vagrant halt
or
vagrant destroy (Again, when you are ready to work again, just issue a vagrant up. The benefit of this is that no cruft is left on your machine.)

[modifier] Liste de VM et status

vagrant status
or
vagrant status vmname

[modifier] Plugins (usually RubyGems)

vagrant plugin list
vagrant plugin install <name>...
vagrant plugin update
vagrant plugin update [<name>]
vagrant plugin license <name> <license-file>
vagrant plugin uninstall <name> [<name2> <name3> ...]

[modifier] snapshot

vagrant snapshot
vagrant snapshot push
vagrant snapshot pop
vagrant snapshot save
vagrant snapshot restore
vagrant snapshot list
vagrant snapshot delete

[modifier] Astuces

  • Proxy pour box
Définir les varialbes d'env:
http_proxy=http://yourproxy:8080
https_proxy=http://yourproxy:8080
no_proxy=localhost,127.0.0.1
  • proxy dans VM
Install proxyconf:
vagrant plugin install vagrant-proxyconf

Configure your Vagrantfile:
config.proxy.http     = "http://yourproxy:8080"
config.proxy.https    = "http://yourproxy:8080"
config.proxy.no_proxy = "localhost,127.0.0.1"
Outils personnels