Ansible-lint in the Ansible PPA is broken?

Dear Colleagues,

Who are the maintainers of the Ansible PPA and to whom could I address this issue ansible and ansible-lint in the PPA are probably incompatible · Issue #4827 · ansible/ansible-lint · GitHub ?

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'

Ansible and ansible-core comes from: Ansible in Launchpad

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.)

The version you’re showing (6.17.2-1) seems to come from the system repositories: https://packages.ubuntu.com/noble/ansible-lint

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?

@Victor_Sudakov I wonder if we can help with the underlying issue. What exactly isn’t working with the latest version of Ansible Core?

Hello @gundalow , you can look at ansible and ansible-lint in the PPA are probably incompatible · Issue #4827 · ansible/ansible-lint · GitHub for more details. In short, any invocation of ansible-lint outputs the following error:


$ 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'


@Victor_Sudakov Another option to make sure you get versions that match is to use a Python package manager instead of the Ubuntu package manager.

I recommend uv which can be much faster than pip and also easy to use.

To install uv

curl -LsSf https://astral.sh/uv/install.sh | sh

From there, you can use uv run to run either command. It will download and cache them at ~/.cache/uv without polluting your system packages:

uvx ansible --version
uvx ansible-lint --version 

uv has options to permanently install the packages at a path as well.

The underlying issue is that the ppa provides package names that override those that available in the ubuntu repos.

As a result, when you install ansible-lint from the ubuntu repo, it has a dep on ansible/ansible-core and is pulling that from the PPA.

However, the version of ansible-lint from the ubuntu repos is not compatible with the version of ansible-core from the PPA.

Basically, in ansible-core 2.19+ this import no longer exists: ansible.parsing.yaml.constructor

1 Like

@sivel Why is ansible-lint not in the ansible PPA and are there any chances to have it included there?

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).

I agree that a system package would be ideal.

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.

uv pip install --system ansible-lint

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.

But maybe I’m wrong, and it’s not that bad. If you want to know how hard packaging ansible-lint actually is, you need to compare the list here: ansible-lint/pyproject.toml at 43e758bad47344f1ce7b699c0020299f486a8026 · ansible/ansible-lint · GitHub to Ubuntu’s package repo and the versions shown there. See whether you can find all the packages, and whether their versions are new enough.

1 Like

@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.

The uvx shortcut works when the command name exactly matches a package name.

uv can still be used to install packages in the usual way, just like pip. I recommend checking the uv docs to see the options.

Having to run each time something like uvx --from=ansible-core ansible-console ... is still not friendly :slight_smile:

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: