0

Would appreciate help in using Vagrant and Ansible to spin-up and provision virtual servers managed by Hyper-V on Windows 11. Currently, I have the latest version of Vagrant (2.4.0) installed on both Windows 11 and in WSL2 (Ubuntu). Ansible is installed on Ubuntu in WSL2.

My assumption is to run Vagrant and Ansible within Ubuntu. I've tried to run vagrant up but found I had to run as admin using sudo vagrant up. I'm currently receiving this error message when running within Ubuntu:

Vagrant failed to initialize at a very early stage:

The executable 'cmd.exe' Vagrant is trying to run was not found in the PATH variable. This is an error. Please verify this software is installed and on the path.

After reading a number of blog posts and Vagrant documentation files, I've modified my ~/.zshrc file to include:

export PATH=$PATH:/mnt/c/windows/system32
export PATH=$PATH:/mnt/c/ProgramData/Microsoft/Windows/Hyper-V
export PATH=$PATH:/mnt/c/Windows/System32/WindowsPowerShell/v1.0
export VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH="/mnt/c/Users/<my username>/"
export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"
export VAGRANT_DEFAULT_PROVIDER=hyperv

I've also verified that Ubuntu is running the the vagrant installation within Ubuntu and not Windows via which vagrant returns: /usr/bin/vagrant.

If I type cmd.exe within Ubuntu, it does execute windows command shell. I'm assuming the problem is still with access rights for vagrant.

1 Answer 1

0

Discovered these changes were necessary to get past this error.

  1. Run Windows Terminal as Admin. I was just opening Windows Terminal normally then assumed if I just ran sudo vagrant up I'd be okay - nope, not the case. Gotta right-click on Windows Terminal, select "Run as Admin".
  2. The environment variable VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH was correctly set but I need to put my Vagrant directory within that hierarchy. That is, the Vagrantfile, etc. Then run the vagrant commands from that directory (which is in Window) but within Ubuntu via WSL2.
  3. Don't use sudo vagrant up - when I run as that I get the error originally cited in this question. However, since I'm running Windows Terminal as Admin, just execute vagrant up.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .