-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Appendix A - Vagrant with VirtualBox within WSL2 to run ansible-for-devops VMs #291
Comments
Well that's odd. That weird bug is due to some strange issue (microsoft/terminal#280 (comment)) in the console's font checking that drops it out from using Consolas. The solution is to use Lucida instead. Weird flex, but ok? |
I was getting 'Connection refused' for SSH, so I tried setting a different port for SSH in the Vagrantfile:
Then on next start, the Windows firewall seemed to notice the difference, so I allowed the connection: But I still couldn't get an SSH connection on that port. I wonder if it's a windows/WSL networking issue :/ |
I think... unfortunately, I'm going to have to give up on this for now at least. I was so close. Vagrant builds the VM, I can see it's running and booted, but it doesn't seem like a private IP / host-only network is configured correctly (e.g. the |
Adding |
Yeah... so I give up for now. I was so close, too! |
Opened new upstream issue: hashicorp/vagrant#11716 |
More attempts: Created new
Modified
Copied insecure_private_key from Windows side to Linux so I could control permissions (otherwise it's always read as 0777):
Ran
So... yay! But this is quite a clunky way to do things. But at least I could get it to work. |
I randomly get the following error about every third playbook run from within WSL2:
It seems to maybe be yet another weird filesystem related issue? Or maybe networking between WSL2 and the Windows host? It never happens on the same task twice. I'm also getting checksum errors, too, for example in NPM:
And then on the next run I got the warning:
Also getting the following for most Git operations (though sometimes they succeed?!):
If anyone says Windows now has 'as seamless of Linux integration as macOS' I think I might slap them with a trout 🐟 . |
I've gone through the same trouble trying to get Vagrant to work on WSL2. I think the core problem at the moment though is that VirtualBox doesn't really work with Hyper-V even if they pretend to. To highlight that. just try to create manually a virtual machine from the VirtualBox UI and install Ubuntu on it. You'll see that the box keeps failing randomly during install (I tried a few times, with different ISOs and the install most often reports corrupted files on the media) or later (I managed to go through the install process once and then it was hanging or APT would report corrupted downloads with a different hash evey time). I think this discussion on the VirtualBox forum sums it up. I'm keen to give Microsoft and VirtualBox a couple of months to sort that stuff out since WSL2 has just come out for the general public. But if I get the time I'll follow these few leeds to try to progress:
|
The current state of this is quite strange as my development stack is mostly relying on Docker + Vagrant/VirtualBox.
So my current situation is I'm running Linux (as the host OS) for development... |
Also found this today:
|
I've adjusted Appendix A to be more aware of the changes to the setup process in later versions of Windows 10, and also added a warning referencing this GitHub issue, so Windows users can follow it as I hopefully—over time—am able to figure out how to get all this book's examples running more seamlessly under WSL. |
Thanks for the hard work troubleshooting and documenting your issue, @geerlingguy. I have been dealing with this same issue on version 2.2.13. |
Has there been any update on this? I've tried everything and just can't get past the point where I run either Vagrant up or provision. I've gotten many different errors, from getting stuck on "SSH auth method private key", problems with ansible connecting to localhost via ssh. It's obviously a problem with the SSH key, but I'm truly running out of things to try. I even temporarily gave up on the Windows solution and installed Ubuntu on a VM to only discover my computer didn't support virtualization for nested VMs... so now I'm back to hoping this will work someday. I appreciate all of the hard work you've done @geerlingguy despite not hearing from the actual team at Vagrant. Edit: Here's the logs of what I get when running vagrant up when ansible can't connect:
|
I would also like to know if there's any updates. Just bought the Ansible for Devops book, trying to follow along with my Windows machine but I can't get through Chapter 2. Tried installing through pip and the official installation for Ubuntu through Ansible's docs, but nothing is working. |
The error message, "Failed to connect to the host via ssh: ssh: connect to
host 127.0.0.1 port 2222: Connection refused" is the first place to check.
Since you're running under WSL2, it could be the firewall on the Windows
laptop denying connections to 127.0.0.1:2222, or the firewall in the Ubuntu
WSL2 instance.
As a start, try disabling the Windows firewall as well as the Ubuntu/WSL2
instance firewall and see if the issue resolves itself.
Running without a firewall is a bad thing, so if that works you'll need to
re-enable both and read up on how to open the required port(s) in each
firewall.
Dan
…On Thu, Feb 11, 2021 at 2:48 AM Jesse Kroon ***@***.***> wrote:
Has there been any update on this? I've tried everything and just can't
get past the point where I run either Vagrant up or provision. I've gotten
many different errors, from getting stuck on "SSH auth method private key",
problems with ansible connecting to localhost via ssh. It's obviously a
problem with the SSH key, but I'm truly running out of things to try.
I even temporarily gave up on the Windows solution and installed Ubuntu on
a VM to only discover my computer didn't support virtualization for nested
VMs... so now I'm back to hoping this will work someday.
I appreciate all of the hard work you've done @geerlingguy
<https://github.com/geerlingguy> despite not hearing from the actual team
at Vagrant.
Edit: Here's the logs of what I get when running vagrant up when ansible
can't connect:
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'bento/ubuntu-20.04' version '202012.23.0' is up to date...
==> default: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> default: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
[sudo] password for ___:
==> default: Running provisioner: ansible...
default: Running ansible-galaxy...
- changing role composer from 1.9.0 to 1.9.0
- downloading role 'composer', owned by geerlingguy
- downloading role from https://github.com/geerlingguy/ansible-role-composer/archive/1.9.0.tar.gz
- extracting composer to /mnt/c/test/trellis/vendor/roles/composer
- composer (1.9.0) was installed successfully
- changing role ntp from 2.2.0 to 2.2.0
- downloading role 'ntp', owned by geerlingguy
- downloading role from https://github.com/geerlingguy/ansible-role-ntp/archive/2.2.0.tar.gz
- extracting ntp to /mnt/c/test/trellis/vendor/roles/ntp
- ntp (2.2.0) was installed successfully
- changing role logrotate from v0.0.5 to v0.0.5
- downloading role 'logrotate', owned by nickhammond
- downloading role from https://github.com/nickhammond/ansible-logrotate/archive/v0.0.5.tar.gz
- extracting logrotate to /mnt/c/test/trellis/vendor/roles/logrotate
- logrotate (v0.0.5) was installed successfully
- changing role swapfile from v2.0.32 to v2.0.32
- downloading role 'swapfile', owned by oefenweb
- downloading role from https://github.com/Oefenweb/ansible-swapfile/archive/v2.0.32.tar.gz
- extracting swapfile to /mnt/c/test/trellis/vendor/roles/swapfile
- swapfile (v2.0.32) was installed successfully
- changing role mailhog from 2.2.0 to 2.2.0
- downloading role 'mailhog', owned by geerlingguy
- downloading role from https://github.com/geerlingguy/ansible-role-mailhog/archive/2.2.0.tar.gz
- extracting mailhog to /mnt/c/test/trellis/vendor/roles/mailhog
- mailhog (2.2.0) was installed successfully
[WARNING]: - dependency geerlingguy.daemonize from role mailhog differs from
already installed version (1.2.1), skipping
default: Running ansible-playbook...
PLAY [Set ansible_python_interpreter] ******************************************
TASK [python_interpreter : Get Ubuntu version] *********************************
System info:
Ansible 2.8.0; Vagrant 2.2.14; Linux
Trellis version (per changelog): "Use Python 3 for `ansible_local` Vagrant provisioner"
---------------------------------------------------
Failed to connect to the host via ssh: ssh: connect to host 127.0.0.1 port
2222: Connection refused
fatal: [default]: UNREACHABLE! => {"changed": false, "unreachable": true}
PLAY RECAP *********************************************************************
default : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.```
I would also like to know if there's any updates. Just bought the Ansible
for Devops book, trying to follow along with my Windows machine but I can't
get through Chapter 2. Tried installing through pip and the official
installation for Ubuntu through Ansible's docs, but nothing is working.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#291 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAISQEYY6QMOHPIO55KVHMTS6OKURANCNFSM4OGHLQYQ>
.
--
***************** ************* *********** ******* ***** *** **
"If you wish to make an apple pie from scratch,
you must first invent the universe."
-- Carl Sagan
"Quis custodiet ipsos custodes?"
(Who can watch the watchmen?)
-- from the Satires of Juvenal
"I do not fear computers, I fear the lack of them."
-- Isaac Asimov (Author)
** *** ***** ******* *********** ************* *****************
|
Hi, I've just started with the book and this was my first issue. I fixed it changing the host IP in the Vagrantfile
After that, I have no more |
This took me some time to figure out, but here is my complete solution:
|
I have the same exact issue . Have been tearing my hair for the past few hours :// |
I mentioned this back in February, but it's worth mentioning it again - ensure your Windows firewall is still turned off. I have had problems with Microsoft re-enabling the Firewall after patches even though I know I disabled it in the settings just a couple days before. The build script I ended up using had the "disable Windows Firewall" portion at the beginning, and an "enable Windows Firewall" at the end just so I was slightly more protected. |
I ran into the |
[Severely edited] In each case, I added the line to the Vgrantfile that Jeff mentioned Here's the hack, I'm running my Ubuntu distro in WSL version 1. To be clear, I have wsl 2 installed, but I'm telling wsl 2 to run Ubuntu as wsl 1. I didn't come up with on my own, it was the result of 3 - 5 hours of research last week. Here's the instructions on how to change the runnnig WSL version. Instructions: Open a command prompt as administrator Shut down the distro you want to run vagrant on Change the wsl version on an existing shell On my machine this looked like Start a new wsl window and try it out. I would love feedback if this ugly horrible hack worked for you. |
Is there any update on this issue or maybe an easy solution to use Vagrant with WSL 2 without VirtualBox? I have a complex setup with WSL 2, Docker etc. and trying the different suggestions don't work. WSL 1 doesn't work for me either because then I would have to split a project into multiple parts or duplicate it because the working environment depends on WSL 2. Thanks. |
I've just gotten this working. WSL2, Vagrant 2.2.19 using @ozboss process. Nothing special in the
The fixes were:
|
Thanks @jshank. It works. |
Software to unzip the file isn't mentioned, so running the "unzip" command will fail. I ran this command to install it within WSL2: sudo apt-get install zip unzip -y |
I'm unable to get 2.2.19 installed successfully. Regardless of whether I download the file from Hashicorp's website, or install it via apt-get, I am left with:
|
For anyone that wants an alternative to messing with WSL, I found the following to be a very nice workaround, to work through the book material on Windows.
|
Hey @geerlingguy, I was able to get around this by installing the virtualbox_WSL2 vagrant plugin: |
Updatedon't do this I broke ansible while doing this. This link looks promising: https://devblogs.microsoft.com/commandline/integrate-linux-commands-into-windows-with-powershell-and-the-windows-subsystem-for-linux/ I can run nano from inside windows though Update:
|
yes. i agree with his solution. for me, i tried installing the |
Since Windows 11 version 22H2, WSL2 can use the setting
I was wondering if anyone has tried this new setting and if it fixes all the issues around wsl2 + vagrant + ansible. |
I think it may finally work, but there are some caveats.
Following my work on Episode 14 of Ansible 101 (see #289), I found you have to do the following:
a.
wget https://releases.hashicorp.com/vagrant/2.2.9/vagrant_2.2.9_linux_amd64.zip
b.
unzip vagrant_2.2.9_linux_amd64.zip
c.
sudo mv ./vagrant /usr/local/bin/vagrant
d.
export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"
e.
vagrant --version
1cd
into a/mnt/c
directory (like/mnt/c/Users/jgeerling/Downloads
) and clone or otherwise put the ansible-for-devops repository contents in there.cd
into one of the ansible-for-devops example directories (e.g.drupal
).Vagrantfile
and make sure to disable the default shared folder (add lineconfig.vm.synced_folder '.', '/vagrant', disabled: true
).2vagrant up
from that directory.1 It seems that every time I run a
vagrant
command, the Bash terminal window is reverted to 'raster' fonts at a very tiny size, and I have to go into the window preferences to revert back to Consolas / 24 pt... Very weird.2 There's an issue for supporting shared folders within the WSL2 environment here. This might not be needed in the future.
The text was updated successfully, but these errors were encountered: