vscode-ansible icon indicating copy to clipboard operation
vscode-ansible copied to clipboard

Ansible is unable to load correctly in WSL+venv config

Open maciejduk opened this issue 2 years ago • 2 comments

Summary

When I open a repository using WSL on Windows, everything works except for the extension. See error message below.

image

It seems to load the virtual environment correctly, but then extension issues commands without /bin folder, which ofcourse causes a 'missing file' error.

Extension version

0.14.71

VS Code version

1.71.2

Ansible Version

(ansible) maciej@wsl:/mnt/c/DevOps/ip-ansible-servicenow$ ansible --version
ansible [core 2.13.4]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/maciej/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/maciej/.venv/ansible/lib/python3.8/site-packages/ansible
  ansible collection location = /home/maciej/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/maciej/.venv/ansible/bin/ansible
  python version = 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0]
  jinja version = 3.1.2
  libyaml = True

OS / Environment

Windows 10 WSL Ubuntu 20.04 ansible-lint 6.7.0 using ansible 2.13.4

(ansible) maciej@wsl:/mnt/c/DevOps/ip-ansible-servicenow$ which ansible-config /home/maciej/.venv/ansible/bin/ansible-config (ansible) maciej@wsl:/mnt/c/DevOps/ip-ansible-servicenow$ ansible-config --version ansible-config [core 2.13.4] config file = /etc/ansible/ansible.cfg configured module search path = ['/home/maciej/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /home/maciej/.venv/ansible/lib/python3.8/site-packages/ansible ansible collection location = /home/maciej/.ansible/collections:/usr/share/ansible/collections executable location = /home/maciej/.venv/ansible/bin/ansible-config python version = 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0] jinja version = 3.1.2 libyaml = True

image

Relevant log output

No response

maciejduk avatar Oct 04 '22 09:10 maciejduk

Hi, no idea if this helps you, but I had a similar issue yesterday. I am using a python virtual environment as well – but on native Ubuntu, not on WSL. What helped in my case was setting ./.venv/bin/python3 as Interpreter Path in the workspace settings (which imho should be automatically set without the need of manual intervention).

redtux avatar Oct 05 '22 18:10 redtux

I have tried that and no matter how many paths I setup, there is always something from this extension trying to open from the wrong folder - one up from bin/ causing errors.

maciejduk avatar Oct 06 '22 08:10 maciejduk

I'm not sure if that will fix your issue, but I had to set the settings in the actual project I was working on. (Not in the settings file which is on windows.)

// at the root of the project
.vscode/
  settings.json
{
  ...
  "ansible.python.interpreterPath": "/pathtoyourproject/venv/bin/python3",
  "ansible.ansible.path": "/pathtoyourproject/venv/bin/ansible",
}

AppeninTerenceBARBE avatar Dec 02 '22 21:12 AppeninTerenceBARBE

The fix to this is to add appropriate paths in the settings as mentioned by @AppeninTerenceBARBE above.

If using virtual environments, you can simply add this setting, and it should work:

ansible.python.activationScript: path/to/venv/activate-script

This will be used to run commands in a Python virtual environment

priyamsahoo avatar Feb 07 '23 11:02 priyamsahoo