Ansible-lint hook no longer works with pre-commit 4.3.0

Hello,

I have recently update pre-commit from 4.2.0 to 4.3.0. I use it with ansible-lint in this way:

- repo: https://github.com/ansible/ansible-lint
    rev: v25.1.0
    hooks:
      - id: ansible-lint
        additional_dependencies:
          - ansible>=9.8.0,<10.0.0
          - ansible-compat==24.10.0

With pre-commit 4.2.0 is all fine. With pre-commit 4.3.0 I see

Ansible-lint.............................................................Failed
- hook id: ansible-lint
- exit code: 1

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/root/.cache/pre-commit/repozusqqq7n/py_env-python3.12/lib/python3.12/site-packages/ansiblelint/__main__.py", line 50, in <module>
    from ansiblelint import cli
  File "/root/.cache/pre-commit/repozusqqq7n/py_env-python3.12/lib/python3.12/site-packages/ansiblelint/cli.py", line 13, in <module>
    from ansiblelint.config import (
  File "/root/.cache/pre-commit/repozusqqq7n/py_env-python3.12/lib/python3.12/site-packages/ansiblelint/config.py", line 118, in <module>
    PROFILES = yaml_from_file(Path(__file__).parent / "data" / "profiles.yml")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.cache/pre-commit/repozusqqq7n/py_env-python3.12/lib/python3.12/site-packages/ansiblelint/loaders.py", line 40, in yaml_from_file
    with open(str(filepath), encoding="utf-8") as content:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/root/.cache/pre-commit/repozusqqq7n/py_env-python3.12/lib/python3.12/site-packages/ansiblelint/data/profiles.yml'

Do you know how to fix this?
I tried to open an issue on pre-commit, but if I understand well they say that this is not supported.

Thank you
Kind Regards
Marco

According to your pre-commit bug report, the file that can’t be found is:

/root/.cache/pre-commit/repozusqqq7n/py_env-python3.12/lib/python3.12/site-packages/ansiblelint/data/profiles.yml

Locally, I used uv to install Python 3.12 and the latest ansiblelint package in isolated environment to see if it includes a data/profiles.yml file and it does. Here’s what I got on my system:

./lib/python3.12/site-packages/ansiblelint/data/profiles.yml

That suggests that the problem with the file being “not found” is not in /that/ part of the path, but further up the tree in the part that pre-commit controls. Combined with your inside that it worked in pre-commit 4.2 but not 4.3 does suggest it’s a bug on their end.

Also, if you not running in a virtual machine or container, consider not using the root account for development, which brings security risks.

Hello Mark,

yes, I have the profile:

ansible [core 2.16.14]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.12/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.12.9 (main, Aug 14 2025, 00:00:00) [GCC 11.5.0 20240719 (Red Hat 11.5.0-5.0.1)] (/usr/bin/python3.12)
  jinja version = 3.1.6
  libyaml = True

ansible-lint 25.1.0 using ansible-core:2.16.14 ansible-compat:24.10.0 ruamel-yaml:0.18.16 ruamel-yaml-clib:0.2.14

# ll /usr/local/lib/python3.12/site-packages/ansiblelint/data/profiles.yml
-rw-r--r-- 1 root root 4.0K Oct 31 11:40 /usr/local/lib/python3.12/site-packages/ansiblelint/data/profiles.yml

For what I can understand it seems that the problem is in pre-commit (4.3.0 only), but I don’t know how to better explain this in the issue.

Thank you, always welcome these hints. I run podman as an unprivileged user (rootless), with processes in the container running as root.

Thank you
Kind Regards
Marco