Skip to content

Vagrant is not working on EC2 Windows

0

Hi AWS, I am working on some ansible playbooks and I am running those using Vagrantfile. The steps I followed for installing vagrant are:

  1. Install WSL2, and install Ubuntu in WSL2.
  2. Install VirtualBox (I'm running 6.1.x --> 6.1.48)
  3. Inside WSL2/Ubuntu/Bash environment, install Vagrant:
    1. wget https://releases.hashicorp.com/vagrant/2.2.6/vagrant_2.2.6_linux_amd64.zip
    2. unzip vagrant_2.2.6_linux_amd64.zip
    3. sudo mv ./vagrant /usr/local/bin/vagrant
    4. export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"
    5. vagrant --version
  4. cd into a /mnt/c directory (like /mnt/c/Users/arjung/Projects) and clone or otherwise put the ansible-for-devops repository contents in there.
  5. cd into one of the ansible-for-devops example directories.
  6. Edit the Vagrantfile and make sure to disable the default shared folder (add line config.vm.synced_folder '.', '/vagrant', disabled: true).
  7. Run vagrant up from that directory.

As a pre-requisite I have enabled Hyper-V which is required in order to work with Vagrant and I have enabled it using the script I attached (hyperv.bat) below:

pushd "%~dp0"

dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txt

for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i"

del hyper-v.txt

Dism /online /enable-feature /featurename:Microsoft-Hyper-V -All /LimitAccess /ALL

pause

I am also attaching the Ansible Playbook and Vagrantfile code.

Ansible Playbook:

---
- name: Set up NTP on all servers
  hosts: all
  become: true
  tasks:
    - name: Ensure NTP is installed
      yum: 
        name: chrony
        state: present
    - name: Ensure NTP is running
      service: 
        name: chronyd 
        state: started 
        enabled: yes

Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "geerlingguy/centos7"
  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "playbook.yml"
  end
end

The vagrant version is same both for PowerShell and WSL2 i.e. 2.2.6, but when I ran vagrant up, I am getting the error below:

Bringing machine 'default' up with 'hyperv' provider...
==> default: Verifying Hyper-V is enabled...
An error occurred while executing a PowerShell script. This error
is shown below. Please read the error message and see if this is
a configuration error with your system. If it is not, then please
report a bug.

Script: check_hyperv.ps1
Error:

Access is denied
At line:1 char:166
+ ... pts\utils'; &('\\wsl.localhost\Ubuntu-20.04\tmp\.mount_vagranojakaW\u ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException

Please suggest.

asked 2 years ago119 views
1 Answer
0

It seems that the error you're encountering is related to permission issues when running the PowerShell script within WSL2 for Vagrant with the Hyper-V provider. The "Access is denied" error suggests that Vagrant might not have sufficient permissions to execute the script for Hyper-V. You can try running your terminal as an administrator, which may resolve this issue. Additionally, ensure that Hyper-V is fully enabled, and that you have the latest version of Vagrant and VirtualBox compatible with Hyper-V. If this persists, you could also check Vagrant's compatibility with WSL2 and Hyper-V for potential workarounds or updates.

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.