Skip to content
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

Unexpected behavior resolving collections, if ansible-lint is executed outside project dir #3957

Open
xrow opened this issue Dec 21, 2023 · 3 comments
Labels

Comments

@xrow
Copy link

xrow commented Dec 21, 2023

Summary

Issue resolving paths to local collections when ansible-lint is not executed in project dir. It loos like tit will not alter or change the path from collections_path with is ./.

Issue Type
  • Bug Report
OS / ENVIRONMENT
[root@localhost ansible]# ansible-lint --version
ansible-lint 6.22.0 using ansible-core:2.15.6 ansible-compat:4.1.10 ruamel-yaml:None ruamel-yaml-clib:None
A new release of ansible-lint is available: 6.22.0 → 6.22.1 Upgrade by running: pip install --upgrade ansible-lint
  • ansible installation method: pip
  • ansible-lint installation method: pip
STEPS TO REPRODUCE

have a local collection with collections_path = ~/.ansible/collections:/usr/share/ansible/collections:./

[root@localhost infrastructure]# ansible-lint ansible/
WARNING  Listing 4 violation(s) that are fatal
syntax-check[specific]: the role 'xxx.infrastructure.vault' was not found in /scm/infrastructure/ansible/ansible_collections/xxx/infrastructure/playbooks/roles:/root/.cache/ansible-compat/9fec08/roles:/root/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/scm/infrastructure/ansible/ansible_collections/xxx/infrastructure/playbooks
ansible/ansible_collections/xxx/infrastructure/playbooks/local.yml:18:15

syntax-check[missing-file]: Unable to retrieve file contents
ansible/playbooks/add-chart.yml:1:1 Could not find or access '/scm/infrastructure/ansible/playbooks/xxx.infrastructure.local' on the Ansible Controller.

syntax-check[missing-file]: Unable to retrieve file contents
ansible/playbooks/build.yml:1:1 Could not find or access '/scm/infrastructure/ansible/playbooks/xxx.infrastructure.local' on the Ansible Controller.

syntax-check[missing-file]: Unable to retrieve file contents
ansible/playbooks/clean-all.yml:1:1 Could not find or access '/scm/infrastructure/ansible/playbooks/xxx.infrastructure.local' on the Ansible Controller.


                    Rule Violation Summary                     
 count tag                        profile rule associated tags 
     3 syntax-check[missing-file] min     core, unskippable    
     1 syntax-check[specific]     min     core, unskippable    

Failed: 4 failure(s), 0 warning(s) on 43 files.
A new release of ansible-lint is available: 6.22.0 → 6.22.1 Upgrade by running: pip install --upgrade ansible-lint
[root@localhost infrastructure]# ansible-lint -p ansible/
WARNING  Listing 4 violation(s) that are fatal
ansible/ansible_collections/xxx/infrastructure/playbooks/local.yml:18:15: syntax-check[specific]: the role 'xxx.infrastructure.vault' was not found in /scm/infrastructure/ansible/ansible_collections/xxx/infrastructure/playbooks/roles:/root/.cache/ansible-compat/9fec08/roles:/root/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/scm/infrastructure/ansible/ansible_collections/xxx/infrastructure/playbooks
ansible/playbooks/add-chart.yml:1:1: syntax-check[missing-file]: Unable to retrieve file contents
ansible/playbooks/build.yml:1:1: syntax-check[missing-file]: Unable to retrieve file contents
ansible/playbooks/clean-all.yml:1:1: syntax-check[missing-file]: Unable to retrieve file contents

                    Rule Violation Summary                     
 count tag                        profile rule associated tags 
     3 syntax-check[missing-file] min     core, unskippable    
     1 syntax-check[specific]     min     core, unskippable    

Failed: 4 failure(s), 0 warning(s) on 43 files.
A new release of ansible-lint is available: 6.22.0 → 6.22.1 Upgrade by running: pip install --upgrade ansible-lint
[root@localhost infrastructure]# cd ansible/ && ansible-lint .
WARNING  Skipped installing collection dependencies due to running in offline mode.

Passed: 0 failure(s), 0 warning(s) on 5 files. Last profile that met the validation criteria was 'production'.
A new release of ansible-lint is available: 6.22.0 → 6.22.1 Upgrade by running: pip install --upgrade ansible-lint
Desired Behavior

ansible-lint -p ansible/ shall work the same as cd ansible/ && ansible-lint .

Possible security bugs should be reported via email to [email protected]

Actual Behavior

See the /scm/infrastructure/ansible missing in the failed run.

[root@localhost ansible]# ansible-lint -p . -vvvv
INFO     Set ANSIBLE_COLLECTIONS_PATH=/root/.cache/ansible-compat/0cb87f/collections:/root/.ansible/collections:/usr/share/ansible/collections:/scm/infrastructure/ansible
[root@localhost infrastructure]# ansible-lint -p ansible/ -vvvv
INFO     Set ANSIBLE_COLLECTIONS_PATH=/root/.cache/ansible-compat/9fec08/collections:/root/.ansible/collections:/usr/share/ansible/collections

Related: ansible/ansible-compat#343

@xrow xrow added bug new Triage required labels Dec 21, 2023
@ssbarnea
Copy link
Member

I think that this is not a bug because when you pass -p you force ansible lint to assume a different project instead of the detected one. Different is to be expected.

@Qalthos Qalthos removed the new Triage required label Jan 10, 2024
@zac90
Copy link

zac90 commented Apr 5, 2024

I too am experiencing a similar issue.

I execute ansible-lint from the root dir of the project, it then traverses into a number of different roles which each have molecule files in them. It then fails on each molecule/prepare.yml saying syntax-check[specific]: the role 'xyz.common.rolename' was not found in <big list of search locations> . Yet this collection has already been fetched as apart of the intilization. To get it to run I have to use --exclude molecule/*/prepare.yml otherwise it keeps failing on the syntax-check stage.

@garymm
Copy link
Contributor

garymm commented Apr 11, 2024

I'm also facing this. I also tried setting --config-file. E.g.:

ansible-lint --config-file=./ansible/.config/ansible-lint.yml

But ansible-lint insists on going up to the location of the .git folder rather than the parent directory of the config file (as seen from the log message Identified <repo root> as project root due .git directory.

Has anyone found a work-around?
It's annoying because pre-commit doesn't easily allow changing the CWD when running ansible-lint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

No branches or pull requests

5 participants