Localhost unreachable on Windows Subsystem for Linux (WSL2, Ubuntu) (Git Issue #: 69765)

Hi everyone,

I opened an issue at Github project but unfortunately got closed unexpectedly. I still believe the there are some compatibility problems between Ansible and WSL, because the scenario I described in the issue worked fine on local docker as well as on my vm boxes.

SUMMARY

Unable to establish connection to localhost under Windows Subsystem for Linux (WSL, Ubuntu)

ISSUE TYPE- Bug Report
COMPONENT NAME

Network

ANSIBLE VERSION
ansible 2.9.6
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.8.2 (default, Apr 27 2020, 15:53:34) [GCC 9.3.0]

CONFIGURATION
DEFAULT_LOCAL_TMP(/etc/ansible/ansible.cfg) = /tmp/ansible-local-2309_h96pb5

OS / ENVIRONMENT

OS:
OS Name: Microsoft Windows 10 Pro (Version 1909)
OS Version: 10.0.18363 N/A Build 18363

WSL:
Distributor ID: Ubuntu
Description: Ubuntu 20.04 LTS
Release: 20.04
Codename: focal

STEPS TO REPRODUCE

Run this command:

ansible localhost -m ping

EXPECTED RESULTS

The ping request successfully poerformed, and Ansible returns the following:

localhost | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

ACTUAL RESULTS

The ping request failed. The following error returned:

With the further details exposed by -vvv we can see the error message when it tried to create the temp folder

sleep: cannot read realtime clock

A quick google search brings up an issue on the WSL repo about this problem https://github.com/microsoft/WSL/issues/4898. Looks like there are some workarounds in that post that indicate it’s due to a recent package update that isn’t handled by WSL. Ansible has no guarantees that it will work properly on WSL, while most things are fine you’ve encountered one of those edge cases which stop us from officially supporting/testing Ansible on this platform. There is nothing we can do here but rely on WSL implementing the POSIX syscalls that Ansible relies on.

Thanks

Jordan

Thanks For pointing the direction Jordan!

I was able to solve the problem by installing libc6_2.31 on my WSL Ubuntu. The steps are as following:
Download libc6_2.31-0ubuntu9_amd64.deb.zip
mv libc6_2.31-0ubuntu9_amd64.deb.zip libc6_2.31-0ubuntu9_amd64.deb

sudo dpkg -i libc6_2.31-0ubuntu9_amd64.deb

When I ran “ansible localhost -m ping” again, I was able to get the following:

localhost | SUCCESS => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/bin/python3”
},
“changed”: false,
“ping”: “pong”
}

As Jordan mentioned, this is a problem on the WSL side rather than Ansible itself. Hope the above helps whoever encountered the same problem.