vscode-ansible
vscode-ansible copied to clipboard
Ansible is unable to load correctly in WSL+venv config
Summary
When I open a repository using WSL on Windows, everything works except for the extension. See error message below.
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
Relevant log output
No response
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).
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.
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",
}
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