Vagrant 2.3.0
Annoncée il y a un peu plus d’un an cette version 2.3.0 est le premier pas vers la sortie de la version 3.0 qui est en fait une réécriture complète de l’outil de création d’environnements de développement virtuels d’HashiCorp.
Cette version 2.3.0 est donc le premier pas et ne bouleverse pas encore trop les habitudes. En effet, cette version fournit encore la version écrite en ruby mais elle est accompagnée de la première version alpha de vagrant-go, comme son nom l’indique, elle est écrite en Go.
Sur le site de la documentation de Vagrant-Go ↗ on peut lire ceci : “Cette version de Vagrant-Go reste compatible avec les plugins Vagrant écrit en Ruby ainsi que les fichiers Vagrantfile”. Cool. “Cependant, il y a quelques changements importants dans le fonctionnement de Vagrant-go qui le rendent NON interchangeable avec Vagrant (Ruby)”. Ah mince.
Je vous propose de tester tout de suite cette version de Vagrant-Go, mais avant vérifions que le plugin vagrant-libvirt s’installe correctement.
Installation du plugin vagrant-libvirt avec Vagrant-Go
Je vais tester l’installation du plugin vagrant-libvirt
avec Vagrant-Go
sur
ma configuration devops 2022. Pour
rappel, cette configuration est montée sur une VM hyper-V elle-même créé
avec la version Windows de Vagrant. Elle est basée sur une Ubuntu 22.04.
Info Importante : Vagrant-Go
ne fonctionne pas pour le moment sous Windows !
export VAGRANT_DEFAULT_PROVIDER=libvirtvagrant-go plugin install vagrant-libvirt
This is an experimental version of Vagrant. Please note that some things maynot work as you expect and this version of Vagrant is not compatible with thestable version of Vagrant. For more information about vagrant-go read the docsat https://www.vagrantup.com/docs/experimental/vagrant_go. To disable thiswarning set the environment variable 'VAGRANT_SUPPRESS_GO_EXPERIMENTAL_WARNING'.
Installing the 'vagrant-libvirt' plugin. This can take a few minutes...Installed the plugin 'vagrant-libvirt (0.10.0)'!
Si on souhaite désactiver le message d’erreur il suffit d’exporter la variable
VAGRANT_SUPPRESS_GO_EXPERIMENTAL_WARNING
avec la valeur true
:
export VAGRANT_SUPPRESS_GO_EXPERIMENTAL_WARNING=true
vagrant helpUsage: vagrant [options] <command> [<args>]
-h, --help Print this help.
Common commands: autocomplete manages autocomplete installation on host box manages boxes: installation, removal, etc. cloud manages everything related to Vagrant Cloud destroy stops and deletes all traces of the vagrant machine global-status outputs status Vagrant environments for this user halt stops the vagrant machine help shows the help for a subcommand init initializes a new Vagrant environment by creating a Vagrantfile login package packages a running vagrant environment into a box plugin manages plugins: install, uninstall, update, etc. port displays information about guest port mappings powershell connects to machine via powershell remoting provision provisions the vagrant machine push deploys code in this environment to a configured destination rdp connects to machine via RDP reload restarts vagrant machine, loads new Vagrantfile configuration resume resume a suspended vagrant machine serve start Vagrant server snapshot manages snapshots: saving, restoring, etc. ssh connects to machine via SSH ssh-config outputs OpenSSH valid configuration to connect to the machine status outputs status of the vagrant machine suspend suspends the machine up starts and provisions the vagrant environment upload upload to machine via communicator validate validates the Vagrantfile version prints current and latest Vagrant version winrm executes commands on a machine via WinRM winrm-config outputs WinRM configuration to connect to the machine
For help on any individual command run `vagrant COMMAND -h`
Additional subcommands are available, but are either more advancedor not commonly used. To see all subcommands, run the command`vagrant list-commands`. --[no-]color Enable or disable color output --machine-readable Enable machine readable output -v, --version Display Vagrant version --debug Enable debug output --timestamp Enable timestamps on log output --debug-timestamp Enable debug output with timestamps --no-tty Enable non-interactive output
Revenons à notre plugin vagrant-libvirt
. Je viens de me rendre compte qu’il
s’agit d’une nouvelle version de celui-ci. Sortie un jour après cette
implémentation de Vagrant en Go. Un petit tour dans le changelog ne
montre pas que c’est en relation avec la sortie de cette version, mais apporte
des corrections au plugin.
Maintenant que le plugin est installé vérifions que cela fonctionne.
Test de Vagrant 2.3.0 avec le plugin libvirt
Pour faire mes tests, j’ai repris le Vagrantfile de la IAC du HomeLab sur lequel j’ai lancé l’ancienne version (en ruby) pour vérifier qu’elle fonctionne encore puis la version en Go.
git clone git@gitlab.com:b4288/infra-as-code-homelab.gitClonage dans 'infra-as-code-homelab'...
cd infra-as-code-homelab
cat Vagrantfile
Dont le contenu est :
# -*- mode: ruby -*-# vi: set ft=ruby :
Vagrant.configure(2) do |config|
number_devbox = 2 # Number of master nodes kubernetes cpu = 1 mem = 1024 config.vm.box = "generic/ubuntu2110" # Image for all installations
nodes = [] (0..number_devbox-1).each do |i| nodes[i] = { "name" => "devbox#{i+1}" } end
# Provision VM nodes.each do |node| config.vm.define node["name"] do |machine| machine.vm.hostname = node["name"] machine.vm.provider "libvirt" do |lv| lv.cpus = cpu lv.memory = mem end machine.vm.synced_folder '.', '/vagrant', disabled: true machine.vm.provision "ansible" do |ansible| ansible.playbook = "playbooks/provision.yml" ansible.groups = { "k3s" => ["devbox1"], "libvirt" => ["devbox2"], "all:vars" => { } } end end endend
Allez on lance le bon vieux vagrant up :
Bringing machine 'devbox1' up with 'libvirt' provider...Bringing machine 'devbox2' up with 'libvirt' provider...==> devbox1: Box 'generic/ubuntu2110' could not be found. Attempting to find and install... devbox1: Box Provider: libvirt devbox1: Box Version: >= 0==> devbox1: Loading metadata for box 'generic/ubuntu2110' devbox1: URL: https://vagrantcloud.com/generic/ubuntu2110==> devbox1: Adding box 'generic/ubuntu2110' (v4.1.6) for provider: libvirt devbox1: Downloading: https://vagrantcloud.com/generic/boxes/ubuntu2110/versions/4.1.6/providers/libvirt.boxProgress: 24% (Rate: 6757k/s, Estimated time remaining: 0:04:36)
Au bout de quelques minutes le provisionnement se lance avec le lancement des playbooks Ansible. Pas de problème donc les deux VM sont disponibles.
vagrant ssh devbox1Last login: Wed Aug 17 07:10:28 2022 from 192.168.121.1vagrant@devbox1:~$
Allez on détruit et on teste avec la version en GO :
vagrant destroy -f==> devbox2: Removing domain...==> devbox2: Deleting the machine folder==> devbox1: Removing domain...==> devbox1: Deleting the machine folder
vagrant-go up! ==> devbox2: An error occurred. The error will be shown after all tasks complete. ==> devbox1: Box 'generic/ubuntu2110' could not be found. Attempting to find and install... devbox1: Box Provider: libvirt devbox1: Box Version: >= 0 ==> devbox1: Loading metadata for box 'generic/ubuntu2110' devbox1: URL: https://vagrantcloud.com/generic/ubuntu2110 ==> devbox1: Adding box 'generic/ubuntu2110' (v4.1.6) for provider: libvirt Progress: 8% (Rate: 6739k/s, Estimated time remaining: 0:05:47)
Ah un problème lors de la création de la VM devbox2. D’ailleurs étrange il
re-télécharge la box. Comme indiqué, il ne faut pas mélanger les deux versions.
Je détruis le répertoire .vagrant
et je relance :
vagrant-go up
Bringing machine 'devbox1' up with 'libvirt' provider... Bringing machine 'devbox2' up with 'libvirt' provider...! ==> devbox1: An error occurred. The error will be shown after all tasks complete. ==> devbox2: Box 'generic/ubuntu2110' could not be found. Attempting to find and install... devbox2: Box Provider: libvirt devbox2: Box Version: >= 0 ==> devbox2: Loading metadata for box 'generic/ubuntu2110' devbox2: URL: https://vagrantcloud.com/generic/ubuntu2110 ==> devbox2: Adding box 'generic/ubuntu2110' (v4.1.6) for provider: libvirt devbox2: Downloading: https://vagrantcloud.com/generic/boxes/ubuntu2110/versions/4.1.6/providers/libvirt.box
Idem, alors il s’agit bien d’un problème ! Un peu capricieux
avec les Vagrantfile
contenant plusieurs machines ? Ou, mais oui j’ai installé
une nouvelle version du plugin vagrant-libvirt
.
J’essaie de désinstaller le plugin pour remettre l’ancienne version et Bim :
Uninstalling the 'vagrant-libvirt' plugin...! Running of task plugin uninstall failed unexpectedly
! Error: rpc error: code = Unknown desc = No such file or directory @ rb_check_realpath_internal -/home/vagrant/.local/share/vagrant/default/project/infra-as-code-homelab/plugins/gems/2.7.6 /opt/vagrant/embedded/gems/2.3.0/gems/vagrant-2.3.0/lib/vagrant/bundler.rb:446:in `realpath' /opt/vagrant/embedded/gems/2.3.0/gems/vagrant-2.3.0/lib/vagrant/bundler.rb:446:in `realpath' /opt/vagrant/embedded/gems/2.3.0/gems/vagrant-2.3.0/lib/vagrant/bundler.rb:446:in `block in clean' /opt/vagrant/embedded/gems/2.3.0/gems/vagrant-2.3.0/lib/vagrant/bundler.rb:445:in `delete_if' /opt/vagrant/embedded/gems/2.3.0/gems/vagrant-2.3.0/lib/vagrant/bundler.rb:445:in `clean' /opt/vagrant/embedded/gems/2.3.0/gems/vagrant-2.3.0/lib/vagrant/plugin/manager.rb:229:in `uninstall_plugin' /opt/vagrant/embedded/gems/2.3.0/gems/vagrant-2.3.0/plugins/commands/plugin/action/uninstall_plugin.rb:18:in `call' /opt/vagrant/embedded/gems/2.3.0/gems/vagrant-2.3.0/lib/vagrant/action/warden.rb:48:in `call' /opt/vagrant/embedded/gems/2.3.0/gems/vagrant-2.3.0/plugins/commands/plugin/action/plugin_exists_check.rb:20:in `call' /opt/vagrant/embedded/gems/2.3.0/gems/vagrant-2.3.0/lib/vagrant/action/warden.rb:48:in `call' /opt/vagrant/embedded...%
Aie !!! Bon les grands moyens : on efface le répertoire .vagrant.d
dans la
home directory.
rm -rf ~/.vagrant.drm -rf .vagrant
Pas mieux. En testant avec des Vagrantfile
ne contenant pas plusieurs VM je
n’ai pas rencontré de soucis.
Conclusion
Je note une certaine latence sur la version en GO qui met plus de temps à démarrer les box. Vous l’avez vu au-dessus, ce n’est pas du production-ready. Cette version n’est là pour remonter les problèmes à HashiCorp pour les corriger avant la prochaine version qui sera la 2.4.0. Il y aura certainement des versions 2.3.x corrigeant certains de ces problèmes.
**Ne mélangez pas les deux versions non plus !!! **
La suite
On est encore loin de la sortie de la version 3.0 de Vagrant . Cette version 2.3.0 est le premier pas et sera suivi d’une version 2.4.0 ou cette fois, c’est la version Go qui sera fourni en standard.
Un point positif HashiCorp souhaite conserver la compatibilité avec
l’existant. Mais pour rappel lors de l’annonce du lancement de l’écriture de
Vagrant 3.0, il était annoncé que cette version introduirait de nouvelles
méthodes de configuration, mais conserverait une compatibilité avec les
fichiers Vagrantfiles
. Ces nouvelles méthodes de configuration seront
probablement à base de HCL, le langage maison.
La nouvelle architecture permettra d’exécuter Vagrant sur un hôte distant. Ainsi, il sera possible de partager un environnement Vagrant entre plusieurs membres d’une équipe. Il est indiqué plein de choses comme une configuration centralisée (vagrant-cloud ?), une API et plein d’autres choses.
Hâte de voir tout cela, mais j’ai du mal à saisir : Pourquoi apporter toutes ces fonctionnalités dans Vagrant alors que Terraform les apporte déjà ?