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)
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.
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: