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

406 views
Skip to first unread message

Leo

unread,
Jun 1, 2020, 7:37:47 PM6/1/20
to Ansible Project
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:

localhost | UNREACHABLE! => {
    "changed": false,
    "msg": "Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in \"/tmp\". Failed command was: ( umask 77 && mkdir -p \"` echo /tmp/ansible-tmp-1590770997.3577683-86430694066473 `\" && echo ansible-tmp-1590770997.3577683-86430694066473=\"` echo /tmp/ansible-tmp-1590770997.3577683-86430694066473 `\" ), exited with result 1, stdout output: ansible-tmp-1590770997.3577683-86430694066473=/tmp/ansible-tmp-1590770997.3577683-86430694066473\n",
    "unreachable": true
}
TROUBLESHOOT ACTIONS TAKEN SO FAR
  1. Update ansible.cfg, set remote_tmp to "/tmp"
  2. Reinstalled SSHD and enable ssh on WSL
  3. Tried reinstalling different versions of Ansible (2.5.X - 2.9.X)
  4. Tried setting the connection to local in host file as suggested (new)
  5. Tried force local connection from ansible-playbook command (new)
OBSERVATIONS
  1. I am able to ssh into localhost from local
  2. The command works fine when running inside a docker container
---------------------------------detail output-----------------------------------
```
root@leoli:/mnt/c/Users/leoli# ansible localhost -vvvv -m ping
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]
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Set default localhost to localhost
Parsed /etc/ansible/hosts inventory source with ini plugin
Loading callback plugin minimal of type stdout, v2.0 from /usr/lib/python3/dist-packages/ansible/plugins/callback/minimal.py
META: ran handlers
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: root
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/ansible-tmp-1591053120.0766757-250645184932946 `" && echo ansible-tmp-1591053120.0766757-250645184932946="` echo /tmp/ansible-tmp-1591053120.0766757-250645184932946 `" ) && sleep 0'
localhost | UNREACHABLE! => {
    "changed": false,
    "msg": "Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in \"/tmp\". Failed command was: ( umask 77 && mkdir -p \"` echo /tmp/ansible-tmp-1591053120.0766757-250645184932946 `\" && echo ansible-tmp-1591053120.0766757-250645184932946=\"` echo /tmp/ansible-tmp-1591053120.0766757-250645184932946 `\" ), exited with result 1, stdout output: ansible-tmp-1591053120.0766757-250645184932946=/tmp/ansible-tmp-1591053120.0766757-250645184932946\n, stderr output: sleep: cannot read realtime clock: Invalid argument\n",
    "unreachable": true
}
```

Jordan Borean

unread,
Jun 1, 2020, 8:25:29 PM6/1/20
to Ansible Project
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

Leo

unread,
Jun 2, 2020, 11:02:16 AM6/2/20
to Ansible Project
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:
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. 
Reply all
Reply to author
Forward
0 new messages