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

Ansible Lint misclassifies template folders as roles #1753

Closed
tadeboro opened this issue Oct 23, 2021 · 3 comments · Fixed by #2021
Closed

Ansible Lint misclassifies template folders as roles #1753

tadeboro opened this issue Oct 23, 2021 · 3 comments · Fixed by #2021
Assignees
Labels

Comments

@tadeboro
Copy link
Contributor

tadeboro commented Oct 23, 2021

Summary

When linting roles, Ansible Lint will misclassify subdirectories in the templates directory as roles.

Issue Type
  • Bug Report
Ansible and Ansible Lint details
ansible --version
ansible [core 2.11.6]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/tadej/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/tadej/ansible-community/ansible-lint/venv/lib64/python3.9/site-packages/ansible
  ansible collection location = /home/tadej/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/tadej/ansible-community/ansible-lint/venv/bin/ansible
  python version = 3.9.7 (default, Aug 30 2021, 00:00:00) [GCC 11.2.1 20210728 (Red Hat 11.2.1-1)]
  jinja version = 3.0.2
  libyaml = True

ansible-lint --version
ansible-lint 5.2.1 using ansible 2.11.6
  • ansible installation method: pip
  • ansible-lint installation method: editable install from main branch
OS / ENVIRONMENT

Fedora 34

STEPS TO REPRODUCE
cd /tmp
ansible-galaxy role init test
cd test
curl https://raw.githubusercontent.com/aminvakil/ansible-role-node-exporter/master/meta/main.yml -o meta/main.yml 
rm .travis.yml 
ansible-lint 
git init
git add .
git commit -m "test"
ansible-lint 
for i in *; do cd $i && git submodule add https://github.com/ansible/distro-test-containers/ distro-test && cd ../; done

The output we get is something like this:

WARNING  Listing 1 violation(s) that are fatal
role-name: Role name distro-test does not match ``^[a-z][a-z0-9_]+$`` pattern
templates/distro-test:1
Desired Behaviour

Ansible Lint should ignore anything in the templates directory (and probably also in all other standard role directories).

Actual Behaviour

Ansible Lint treats the subdirectory as a role and outputs all kinds of nonsense when trying to lint unstructured files.

Additional data

The source of the issue is the kind_from_path function. Because template files and folds do not have a dedicated entry in DEFAULT_KINDS, directories under templates classify as roles. We could probably solve this by adding an entry like {"template": "**/templates/*"} to DEFAULT_KINDS, but I did not test this nor did I think much about the consequences this addition might have on the linter.

This issue was discovered by Amin and reported via IRC. Thank you, Amin!

@tadeboro tadeboro added new Triage required bug labels Oct 23, 2021
@ssbarnea
Copy link
Member

Indeed this looks like the something sorted like you mentioned and it should be quite easy to include a test for it. I would start adding the files/folder inside examples for replicating the bug first.

@tadeboro
Copy link
Contributor Author

Replicating this issue with pure folders is not possible. Because Ansible Lint uses git to get a list of files it should inspect, we would need to add a "git boundary" to the folder. Git itself will never report folders in the listing since they contain no content which is what git tracks.

@ssbarnea ssbarnea removed the new Triage required label Jan 10, 2022
@ssbarnea
Copy link
Member

I think it would be ok to ignore templates. Feel free to add a new pattern for that. I think that there are just too many cases where linter would choke on templates, even simple yamllint execution is likely to fail with some templated files.

@ssbarnea ssbarnea self-assigned this Mar 18, 2022
ssbarnea added a commit to ssbarnea/ansible-lint that referenced this issue Mar 18, 2022
ssbarnea added a commit to ssbarnea/ansible-lint that referenced this issue Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants