'molecule lint' seems to process role's files twice.
jghal opened this issue · 6 comments
Issue Type
- Bug report
Molecule and Ansible details
[/work/cloudeng-ci-agent/integration-tests/ansible/myrole]
$ ansible --version
ansible [core 2.12.5]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.8/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.8.10 (default, May 6 2021, 00:05:59) [GCC 10.2.1 20201203]
jinja version = 3.1.2
libyaml = False
[/work/cloudeng-ci-agent/integration-tests/ansible/myrole]
$ molecule --version
molecule 3.6.1 using python 3.8
ansible:2.12.5
azure:0.5.0 from molecule_azure
delegated:3.6.1 from molecule
docker:1.1.0 from molecule_docker requiring collections: community.docker>=1.9.1
ec2:0.4 from molecule_ec2
Molecule installation method (one of):
- pip
Ansible installation method (one of):
- pip
Detail any linters or test runners used:
Desired Behavior
Running molecule lint
with ansible-lint specified as linter in molecule/<scenario>/molecule.yml should only show files once.
Actual Behaviour
The role's files are listed twice in the lint output.
EDIT: I do not see the duplicated output when running ansible-lint
directly from the same directory.
How to reproduce
Init a new role
$ molecule init role test.myrole --driver-name docker
Enable lint in _myrole/molecule/default/molecule.yml
lint: |
ansible-lint
Run molecule lint
$ molecule lint
INFO default scenario test matrix: dependency, lint
INFO Performing prerun...
INFO Set ANSIBLE_LIBRARY=/root/.cache/ansible-compat/a8f7d1/modules:/root/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO Set ANSIBLE_COLLECTIONS_PATH=/root/.cache/ansible-compat/a8f7d1/collections:/root/.ansible/collections:/usr/share/ansible/collections
INFO Set ANSIBLE_ROLES_PATH=/root/.cache/ansible-compat/a8f7d1/roles:/root/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
INFO Using /root/.ansible/roles/test.myrole symlink to current repository in order to enable Ansible to find the role using its expected full name.
INFO Running default > dependency
WARNING Skipping, missing the requirements file.
WARNING Skipping, missing the requirements file.
INFO Running default > lint
WARNING Loading custom .yamllint config file, this extends our internal yamllint config.
WARNING Listing 10 violation(s) that are fatal
meta-incorrect: Should change default metadata: author
../../../../../root/.ansible/roles/test.myrole/meta/main.yml:1
meta-incorrect: Should change default metadata: company
../../../../../root/.ansible/roles/test.myrole/meta/main.yml:1
meta-incorrect: Should change default metadata: license
../../../../../root/.ansible/roles/test.myrole/meta/main.yml:1
meta-no-info: Role info should contain platforms
../../../../../root/.ansible/roles/test.myrole/meta/main.yml:1
meta-incorrect: Should change default metadata: author
meta/main.yml:1
meta-incorrect: Should change default metadata: company
meta/main.yml:1
meta-incorrect: Should change default metadata: license
meta/main.yml:1
meta-no-info: Role info should contain platforms
meta/main.yml:1
fqcn-builtins: Use FQCN for builtin actions.
molecule/default/converge.yml:5 Task/Handler: Include test.myrole
fqcn-builtins: Use FQCN for builtin actions.
molecule/default/verify.yml:8 Task/Handler: Example assertion
You can skip specific rules or tags by adding them to your configuration file:
# .config/ansible-lint.yml
warn_list: # or 'skip_list' to silence them completely
- fqcn-builtins # Use FQCN for builtin actions.
- meta-incorrect # meta/main.yml default values should be changed.
- meta-no-info # meta/main.yml should contain relevant info.
Finished with 10 failure(s), 0 warning(s) on 18 files.
WARNING Retrying execution failure 2 of: a n s i b l e - l i n t
CRITICAL Lint failed with error code 2
I've been able to fix this by adding ..
exclude_paths:
- ./molecule/
- ../
to .ansible-lint but I've noticed that ansible-lint is also linting other roles I have installed through galaxy just recently and there's a related discussion @ ansible/ansible-lint#2067
ansible-lint 6.1.0 using ansible 2.12.5
@isuftin thanks for the workaround. But I do feel since I don't see this duplicated listing of files when running ansible-lint
directly from the same folder, it qualifies as a bug in molecule.
IMHO, this behavior is expected.
As the role test.myrole
is indeed included in a specific Ansible task
in playbook molecule/default/converge
.
And ansible-lint
will try its best to resolve the included role, you can find the detailed information in https://github.com/ansible/ansible-lint/blob/d2671989f63396005b202cb55bb11d2a77a602c6/src/ansiblelint/utils.py#L455-L470.
If the included role can be resolved, the files in it would be parsed.
If can't, it would not be parsed.
https://github.com/ansible/ansible-lint/blob/d2671989f63396005b202cb55bb11d2a77a602c6/src/ansiblelint/utils.py#L491-L501
Without molecule
The current being tested role will not be installed(symlinked) to ANSIBLE_ROLES_PATH
, ~/.ansible/roles
.
The include_role
in molecule/default/converge
would not be resolved, that's to say, it would not be parsed.
That's why I do not see the duplicated output when running ansible-lint directly from the same directory.
With molecule
The current being tested role will be installed(symlinked) to ANSIBLE_ROLES_PATH
. For your case, it's ~/.ansible/roles
.
The include_role
in molecule/default/converge
would be resolved, that's to say, it would be parsed.
That's why The role's files are listed twice in the lint output.
, AKA ../../../../../root/.ansible/roles/xxx
Being expected with current implementation is not mutually exclusive with calling it a bug. Reporting on the files twice is giving me empirically incorrect data. The code doesn't have 10 violations, it has 6. If the data is incorrect, I can't use it for PR approval rules or observing trends in pushed code quality.
You just need to fix 6 violations and 10 would disappear.
Regarding observing trends, exclude_paths
could be added to work around this issue.
Closing as wonfix we are removing lint from molecule in v4