-
Notifications
You must be signed in to change notification settings - Fork 672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ansible-lint does not look for ansible binary inside venv #1507
Comments
This is also a problem, when there is an Ansible within the virtualenv only and no system Ansible at all: File "/usr/lib/python3.8/subprocess.py", line 493, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'ansible' |
Additionally, I ran
(along with the FATAL error up near the top of the installation, but nothing that actually seemed to fail) When I run
|
Your ansible installation is broken and linter detects that. |
@ssbarnea in what way is my ansible installation (which works perfectly in a venv like every other python application) broken, while ansible-lint, which cannot work in a venv, is not broken? |
Read https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#upgrading-ansible-with-pip well, and make use of pip in order to see which ansible packages you have installed there, you will find the problem. |
I am aware of that issue, but I did not have tl;dr for anyone elseTry recreating your virtual environment. If you're using |
@briantist |
I think the described issue is different because it hits an executable installed externally and available on the |
Reiterating on what was discussed on a call: using software installed a virtualenv does not require one to "activate" it in their shell via |
This is a weird one! So ansible-lint does not use the ansible from the venv, but at the same time it does not work without ansible being installed in the venv:
The version should be fine though:
When I install ansible into the venv I get this version:
Which leads to:
However, there is no problem at all when using ansible-lint as pre-commit hook:
Even though the installed packages are identical:
|
That's because of the difference between doing imports vs. subprocess invocations. |
Yeah, I saw that both are used. Probably not a good idea to mix them, but pre-commit seems to do something that makes it work. |
I'm using this straightforward workaround: |
Today I hit this issue. I had ansible-lint installed on the system, but had ansible-core (2.12.1) only installed in the virtual environment (python 3.9.9, venv). Once I removed the global ansible-lint, and installed it in the virtual environment it started to work again. |
It would be nice to be able to configure the ansible bin path to use. Because with pipx we can manage multiple version of ansible by adding a suffix. The current path seems to look for "ansible" bin only.
I have 2 Ansible installed in 2 different venv
|
@Sispheor we will not make this configurable, basically because the only case where ansible-lint would really work is when it is installed inside the same env as ansible, it not only calls ansible but also imports ansible modules at runtime. Mixing two ansible installations would a recipe for pain. You are welcome to test the current patch and report if it works as you expect. |
Note that this patch is designed to operate both before and after the fix for issue ansible#1507. The assertations similar to the pre-patched version must be the ones which fail against the pre-patched code. If these assertations pass but others fail then the problem is likely that the fix for issue ansible#1507 has not been applied.
previous dumb commentI just went through the discussion of this issue and related issues and I'm wondering if it wouldn't be simpler to call ansible executables using the pythonic venv aware way of ${sys.executable} -m ansible[-playbook] <...args>. This would always pick the version of ansible that came as a dependency of ansible-lint, no matter what the venv situation is.I've checked my assumptions and I was wrong, the correct way to call ansible and always hit the correct version of ansible would be to call the main method ( |
@bendem Ansible does not have an official supported way to be called using Python, that is why we call it as subprocess. Still, there is work to make this a supported way, once we get confirmation from core team that we can use it, we will do it as it will also introduce serious speed improvements, saving ~2s per call/file. |
Summary
When ansible-lint is installed inside venv, it is expected that ansible-lint will try to find ansible binary inside venv as well, even when venv is not activated. Instead it looks inside $PATH only.
This results in the following error, when you have ansible 2.9 installed by system packages, and ansible 2.10 along with ansible-lint inside the venv:
ERROR FATAL: Ansible CLI (2.9.6) and python module (2.10.7) versions do not match. This indicates a broken execution environment.
Issue Type
Ansible and Ansible Lint details
OS / ENVIRONMENT
Python 3.8.5
Ubuntu 20.04
STEPS TO REPRODUCE
Desired Behaviour
It is expected to search for ansible binary inside venv, even when venv is not activated
Actual Behaviour
Ansible binary is searched only inside actual $PATH
The text was updated successfully, but these errors were encountered: