Partage
  • Partager sur Facebook
  • Partager sur Twitter

Vagrant +Windows + WSL2 + Hyper-v

"Problème de connexion Vagrant VM" ?

Sujet résolu
18 août 2023 à 18:34:23

Bonjour,

Je suis en train de mettre en place Vagrant sur Windows 11 (Vagrant +Windows + WSL2 + Hyper-v ) histoire d'essayer d'autres modes de travail.


Pour ce faire, je m'appuie sur ce document : https://gist.github.com/HonkinWaffles/ec48e5c37f2c410c07d97cfb0a0d016d

En gros les prérequis :

  • Windows Professionnel - Hyper-V ne peut être installé que sur les systèmes Windows Professionnel ou supérieur
  • WSL2 - En raison des énormes différences entre WSL1 et WSL2, ce guide ne couvrira que la prise en charge de WSL2
  • Virtualisation CPU - Bien que la grande majorité des processeurs modernes prennent en charge la virtualisation, vous devrez peut-être l'activer dans votre BIOS

Ma configuration :

  • Windows 11 familial avec environnement que je qualifierait "Tech / Dev / DevOps" (WSL2-Ubuntu 20.04, Docker Desktop, Hyper-V, logiciels de programmation, etc.)
  • j'utilise Hyper-V et WSL2 depuis un plus d'un an, j’établis des connexions SSH, de ce coté là tout va bien...

j'arrive au stade où je peux effectuer un vagrant up sur le terminal de WSL2 (qui lui est lancé "en tant qu'administateur" car j'ai lu lors de mes recherche que pour travailler sur Hyper-V WSL2 doit être lancé en mode admin)

je crée un dossier sur /mnt/c/, je fais un lien symbolique pour éviter de faire un cd /mnt/c/chemin_du_dossier à chaque vagrant up.

je fais un vagrant up et voici le log d'initialisation :

Bringing machine 'default' up with 'hyperv' provider...
==> default: Verifying Hyper-V is enabled...                                                                                                                  ==> default: Verifying Hyper-V is accessible...                                                                                                               ==> default: Importing a Hyper-V instance                                                                                                                         default: Creating and registering the VM...                                                                                                                   default: Successfully imported VM                                                                                                                             default: Please choose a switch to attach to your Hyper-V instance.
    default: If none of these are appropriate, please open the Hyper-V manager
    default: to create a new virtual switch.
    default:
    default: 1) Externe
    default: 2) Default Switch
    default: 3) WSL
    default:
    default: What switch would you like to use? 3
    default: Configuring the VM...
    default: Setting VM Enhanced session transport type to disabled/default (VMBus)
==> default: Starting the machine...
==> default: Waiting for the machine to report its IP address...
    default: Timeout: 120 seconds
    default: IP: fe80::215:5dff:fe01:6408
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: fe80::215:5dff:fe01:6408:22
    default: SSH username: vagrant
    default: SSH auth method: private key
/opt/vagrant/embedded/lib/ruby/3.1.0/socket.rb:1214:in `__connect_nonblock': Invalid argument - connect(2) for [fe80::215:5dff:fe01:6408]:22 (Errno::EINVAL)
        from /opt/vagrant/embedded/lib/ruby/3.1.0/socket.rb:1214:in `connect_nonblock'
        from /opt/vagrant/embedded/lib/ruby/3.1.0/socket.rb:56:in `connect_internal'
        from /opt/vagrant/embedded/lib/ruby/3.1.0/socket.rb:137:in `connect'
        from /opt/vagrant/embedded/lib/ruby/3.1.0/socket.rb:642:in `block in tcp'
        from /opt/vagrant/embedded/lib/ruby/3.1.0/socket.rb:227:in `each'
        from /opt/vagrant/embedded/lib/ruby/3.1.0/socket.rb:227:in `foreach'
        from /opt/vagrant/embedded/lib/ruby/3.1.0/socket.rb:632:in `tcp'
        from /opt/vagrant/embedded/gems/gems/net-ssh-7.1.0/lib/net/ssh/transport/session.rb:72:in `initialize'
        from /opt/vagrant/embedded/gems/gems/net-ssh-7.1.0/lib/net/ssh.rb:255:in `new'
        from /opt/vagrant/embedded/gems/gems/net-ssh-7.1.0/lib/net/ssh.rb:255:in `start'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/plugins/communicators/ssh/communicator.rb:472:in `block (2 levels) in connect'
        from /opt/vagrant/embedded/lib/ruby/3.1.0/timeout.rb:107:in `block in timeout'
        from /opt/vagrant/embedded/lib/ruby/3.1.0/timeout.rb:36:in `block in catch'
        from /opt/vagrant/embedded/lib/ruby/3.1.0/timeout.rb:36:in `catch'
        from /opt/vagrant/embedded/lib/ruby/3.1.0/timeout.rb:36:in `catch'
        from /opt/vagrant/embedded/lib/ruby/3.1.0/timeout.rb:123:in `timeout'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/plugins/communicators/ssh/communicator.rb:433:in `block in connect'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/retryable.rb:17:in `retryable'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/plugins/communicators/ssh/communicator.rb:432:in `connect'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/plugins/communicators/ssh/communicator.rb:87:in `block in wait_for_ready'
        from /opt/vagrant/embedded/lib/ruby/3.1.0/timeout.rb:107:in `block in timeout'
        from /opt/vagrant/embedded/lib/ruby/3.1.0/timeout.rb:36:in `block in catch'
        from /opt/vagrant/embedded/lib/ruby/3.1.0/timeout.rb:36:in `catch'
        from /opt/vagrant/embedded/lib/ruby/3.1.0/timeout.rb:36:in `catch'
        from /opt/vagrant/embedded/lib/ruby/3.1.0/timeout.rb:123:in `timeout'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/plugins/communicators/ssh/communicator.rb:63:in `wait_for_ready'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/action/builtin/wait_for_communicator.rb:16:in `block in call'

Et il me rend la main avec une VM lancé et apparemment OP sur Hyper-V mais avec l'incapassité de prendre la main dessus, et je ne peut faire un vangrant ssh vu que la connexion s'est mal passé...

Y a t-il quelqu'un qui a eu ce problème et qui pourrait m'aider ? si ça se trouve c'est 3 fois rien mais ce 3 fois rien me bloque depuis 2 jours malgré mes recherches...

  • Partager sur Facebook
  • Partager sur Twitter

L’éternel débutant...

21 août 2023 à 16:06:02

Problème résolu :

j'ai trouvé une nouvelle doc : https://github.com/deluxebrain/wsl-vagrant-hyperv-setup dans la quel le point 7 explique un peu le paramétrage réseau.

la logique (enfin la mienne) m'a fait choisir la 3 et j'ai eu le message du dessus.

je me suis appuyé sur ce fameux point 7 de ce nouveau document et j'ai pris la configuration  "default switch":

"vagrant up" :

==> default: Waiting for machine to boot. This may take a few minutes...                                                                                                         default: SSH address: 172.19.143.184:22
    default: SSH username: vagrant
    default: SSH auth method: private key
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors                                                                                                          are usually good hints as to what may be wrong.                                                                                                                                                                                                                                                                                                           If you're using a custom box, make sure that networking is properly                                                                                                          working and you're able to connect to the machine. It is a common                                                                                                            problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

et il est vrai que pour hyper-V quand je faisait une VM je mettais toujours une connexion "externe" (ou bridgé) du coup j'ai recommencé avec la configuration "externe", le "vagrant up" est allé au bout et je peux me connecter avec un "vagrant ssh"

  • Partager sur Facebook
  • Partager sur Twitter

L’éternel débutant...