Hi AWS, I am working on some ansible playbooks and I am running those using Vagrantfile. The steps I followed for installing vagrant are:
- Install WSL2, and install Ubuntu in WSL2.
- Install VirtualBox (I'm running 6.1.x --> 6.1.48)
- Inside WSL2/Ubuntu/Bash environment, install Vagrant:
- wget https://releases.hashicorp.com/vagrant/2.2.6/vagrant_2.2.6_linux_amd64.zip
- unzip vagrant_2.2.6_linux_amd64.zip
- sudo mv ./vagrant /usr/local/bin/vagrant
- export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"
- vagrant --version
- 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.
- cd into one of the ansible-for-devops example directories.
- Edit the Vagrantfile and make sure to disable the default shared folder (add line config.vm.synced_folder '.', '/vagrant', disabled: true).
- 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.