Hello,
I have a problem with ansible-lint
and its mode to discover paths.
In my develop environment all it’s working fine. I enter the role or collection path, I run ansible-lint
and I see the results of the role or the collection checks.
It’s exciting and I decided to add ansible-lint
to my CI environment too Ie:
[...]
test_job:
stage: test
script:
- ansible-playbook -i /etc/ansible/hosts/main_docker.yml tests/test.yml --syntax-check
- ansible-lint
- ansible-playbook -i /etc/ansible/hosts/main_docker.yml tests/test.yml
Here when I run ansible-lint
I see a lot of errors because the paths are not well detected.
If I run the lint on a role inside a collection, the role is threated as a standalone role, and all collections and roles are checked.
So I run ansible-lint
in verbose mode and I noticed that the problem is:
# ansible-lint -v
INFO Identified / as project root due file system root.
Even if I add a path, the project root is always “/”:
# cd ..
# ansible-lint -v mycollection/
INFO Identified / as project root due file system root.
Ps: the ansible-lint
docs says
positional arguments:
lintables One or more files or paths. When missing it will enable auto-detection mode.
but it seems that it’s not really true, or I don’t understand something, because the discovering path process starts even if I specify a path.
In my develop environment the difference is that the collection is a git project (internal roles are git submodules), so all is working as expected:
# cd <my collection path>
# ansible-lint -v
INFO Identified /root/.ansible/collections/ansible_collections/<namespace>/<name> as project root due .git directory.
In my CI environment with gitlab pipelines I don’t have the .git directories and ansible-lint
always starts checking from “/”.
I’m a little confused about this behaviour. I wonder how to avoid this problem, or I wonder what the best workaround to solve this would be.
Do you have any hints?
The ansible-lint
version is the last:
ansible-lint 24.2.0 using ansible-core:2.16.2 ansible-compat:4.1.11 ruamel-yaml:0.18.5 ruamel-yaml-clib:0.2.8
Thank you very much
Kind Regards
Marco