Short summary of the issue: ansible and ansible-lint in the PPA are probably incompatible, after a recent “apt upgrade”, when I try running ansible-lint, I get the following traceback:
$ ansible-lint
Traceback (most recent call last):
File "/usr/bin/ansible-lint", line 5, in <module>
from ansiblelint.__main__ import _run_cli_entrypoint
File "/usr/lib/python3/dist-packages/ansiblelint/__main__.py", line 39, in <module>
from ansiblelint import cli
File "/usr/lib/python3/dist-packages/ansiblelint/cli.py", line 29, in <module>
from ansiblelint.yaml_utils import clean_json
File "/usr/lib/python3/dist-packages/ansiblelint/yaml_utils.py", line 31, in <module>
from ansiblelint.utils import Task
File "/usr/lib/python3/dist-packages/ansiblelint/utils.py", line 41, in <module>
from ansible.parsing.yaml.constructor import AnsibleConstructor, AnsibleMapping
ModuleNotFoundError: No module named 'ansible.parsing.yaml.constructor'
I’m not sure where ansible-lint comes from, I didn’t find a PPA for it in a quick search.
Is it possible that you installed ansible-lint from the system’s repositories, and not from some PPA? That could explain why it doesn’t work with the PPA. You likely have to install ansible from the system repositories as well to make it work with ansible-lint from there. (My guess is that they use different Python interpreters, and thus are incompatible.)
I have deb https://ppa.launchpadcontent.net/ansible/ansible/ubuntu noble main in /etc/apt/sources.list.d/ppa_ansible_ansible_noble.list. Is there a reliable way to find out from which repositories ansible and ansible-lint are actually installed? Here is the current output on my system:
$ apt list --installed | grep ansible
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
ansible-core/noble,now 2.19.4-1ppa~noble all [installed,automatic]
ansible-lint/noble,now 6.17.2-1 all [installed]
ansible/noble,now 12.2.0-1ppa~noble all [installed]
python3-ansible-compat/noble,now 4.1.11-1 all [installed,automatic]
Does the above look like there is a repository mismatch? Or what command could I use to detect a mismatch?
You may be right and thank you for the hint! After removing the PPA repo, I get the following versions:
ansible-core/noble,now 2.16.3-0ubuntu2 all [installed,automatic]
ansible-lint/noble,now 6.17.2-1 all [installed]
ansible/noble,now 9.2.0+dfsg-0ubuntu5 all [installed]
python3-ansible-compat/noble,now 4.1.11-1 all [installed,automatic]
and ansible-lint seems to be working. So I was erroneously thinking that ansible-lint was coming from the PPA, while it does not seem to be the case.
However, I need to run the PPA version of Ansible because 2.16 is lacking some features I need. Do you have any ideas how I could get a working ansible-lint while keeping the PPA version of ansible?
$ ansible-lint --version
Traceback (most recent call last):
File "/usr/bin/ansible-lint", line 5, in <module>
from ansiblelint.__main__ import _run_cli_entrypoint
File "/usr/lib/python3/dist-packages/ansiblelint/__main__.py", line 39, in <module>
from ansiblelint import cli
File "/usr/lib/python3/dist-packages/ansiblelint/cli.py", line 29, in <module>
from ansiblelint.yaml_utils import clean_json
File "/usr/lib/python3/dist-packages/ansiblelint/yaml_utils.py", line 31, in <module>
from ansiblelint.utils import Task
File "/usr/lib/python3/dist-packages/ansiblelint/utils.py", line 41, in <module>
from ansible.parsing.yaml.constructor import AnsibleConstructor, AnsibleMapping
ModuleNotFoundError: No module named 'ansible.parsing.yaml.constructor'
Thank you @markstos , I’ll give uv a try though I’d strongly prefer to have ansible and ansible-lint installed for all local users and not just myself (which apt does).
You can use uv to install the package at the system-level as well, but there’s chance that it could conflict with other packages installed via the Ubuntu package manager.
For the why, you could also ask: why should it? Someone would have to maintain that, and so far nobody stepped up to do it.
The main problem with ansible-lint is that it has a lot of dependencies. If you package ansible-core, which has a very low number of dependencies out of which several are already packaged by most OSes, you can focus on packaging ansible-core and maybe 1-2 other packages. If you look at ansible : “Ansible” team, you can see it’s resolvelib for some Ubuntu versions, but nothing else.
Now if you want to package ansible-lint, you’ll likely find out that many of its (transitive) transitive dependencies are not yet packaged, or not in the versions ansible-lint requires. Then you have to start packaging these as well, and if these clash with packages Ubuntu already has (which will likely happen, considering that Ubuntu itself has an older version of ansible-lint), you end up in dependency hell and are making the problem you’re seeing here with ansible-lint and ansible-core a lot worse for many other programs that depend on the other dependencies.
That’s why I wouldn’t want to package it in a PPA.
@markstos I have already tried this trick installing ansible-lint from pip or pipx alongside with ansible from the PPA, it did not work because in this case ansible-lint refused to see the installed ansible collections.
It is very unfortunate that ansible-lint is such a headache. I somehow felt it was an integral part of the ansible toolset (like ansible-console etc) and therefore belonged very well with ansible’s other utilities, it is a pity it is not the case.
I recommend uv which can be much faster than pip and also easy to use.
Looks unfriendly at first glance:
$ uvx ansible-playbook --version
× No solution found when resolving tool dependencies:
╰─▶ Because ansible-playbook was not found in the package registry and you require ansible-playbook, we can conclude that your requirements are unsatisfiable.
$ uvx ansible-console
× No solution found when resolving tool dependencies:
╰─▶ Because ansible-console was not found in the package registry and you require ansible-console, we can conclude that your requirements are unsatisfiable.
And still has the same problem I saw when I tried to install ansible-lint from pip/pipx: it does not see the collections
$ uvx ansible-lint workstation.yml
WARNING Listing 1 violation(s) that are fatal
syntax-check[unknown-module]: couldn't resolve module/action 'community.general.locale_gen'. This often indicates a misspelling, missing collection, or incorrect module path.
workstation.yml:20:7
There is a collection path problem somewhere. The “community.general” collection is of course present in the system
$ ansible-galaxy collection list | grep general
community.general 11.4.1
You can use uv or pip to install Python packages, after which they are installed on your machine, and you can the commands without any prefix, like normal.
And still has the same problem I saw when I tried to install ansible-lint from pip/pipx: it does not see the collections
Then I recommend installing the packages normally and setting up collections_paths in your ansible.cfg to point to your path where your collections are stored: