ansible / ansible-lint

ansible-lint checks playbooks for practices and behavior that could potentially be improved and can fix some of the most common ones for you
https://ansible.readthedocs.io/projects/lint/
GNU General Public License v3.0
3.51k stars 666 forks source link

ansible-lint version 6.21 fails to report warnings #3853

Closed rjeffman closed 1 year ago

rjeffman commented 1 year ago
Summary

After updating ansible-lint from 6.20.3 to 6.21.0, it fails to report warnings and stop execution with an exception stack trace.

Issue Type
OS / ENVIRONMENT
ansible-lint --version
ansible-lint 6.21.0 using ansible-core:2.15.5 ansible-compat:4.1.10 ruamel-yaml:0.17.35 ruamel-yaml-clib:0.2.8

Ansible and ansible-lint installation was through pip, in a virtual environment (venv).

python --version
Python 3.11.6
pip --version
pip 23.3 from /tmp/freeipa/lib64/python3.11/site-packages/pip (python 3.11)
STEPS TO REPRODUCE

Run ansible-lint against file test_groups_present_slice.yml in ansible-freeipa collection.

$ ansible-lint --offline --profile production --parseable --force-color tests/group/test_groups_present_slice.yml
Desired Behavior

The same behavior as in ansible-lint 6.20.3 is expected:

$ ansible-lint --offline --profile production --parseable --force-color tests/group/test_groups_present_slice.yml
INFO     Identified /home/rjeffman/Developer/ansible-freeipa as project root due config file /home/rjeffman/Developer/ansible-freeipa/.ansible-lint.
INFO     Set ANSIBLE_LIBRARY=/home/rjeffman/.cache/ansible-compat/c37ee1/modules:plugins/modules:/home/rjeffman/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/home/rjeffman/.cache/ansible-compat/c37ee1/collections:/home/rjeffman/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/home/rjeffman/.cache/ansible-compat/c37ee1/roles:roles:/home/rjeffman/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
INFO     Set ANSIBLE_LIBRARY=/home/rjeffman/.cache/ansible-compat/c37ee1/modules:plugins/modules:/home/rjeffman/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/home/rjeffman/.cache/ansible-compat/c37ee1/collections:/home/rjeffman/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/home/rjeffman/.cache/ansible-compat/c37ee1/roles:roles:/home/rjeffman/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
INFO     Executing syntax check on playbook tests/group/test_groups_present_slice.yml (0.29s)
WARNING  Listing 1 violation(s) that are fatal
tests/group/test_groups_present_slice.yml:14: warning[outdated-tag]: Replaced outdated tag '505' with 'missing-import', replace it to avoid future errors (warning)
Read documentation for instructions on how to ignore specific rule violations.

                      Rule Violation Summary                      
 count tag                   profile rule associated tags         
     1 warning[outdated-tag]         core, experimental (warning) 

Passed: 0 failure(s), 1 warning(s) on 2 files. Profile 'production' was required, and it passed. Rating: 5/5 star
Actual Behavior

An exception is raised and a stack trace is given:

$ ansible-lint --offline --profile production --parseable --force-color tests/group/test_groups_present_slice.yml
INFO     Identified /home/rjeffman/Developer/ansible-freeipa as project root due config file /home/rjeffman/Developer/ansible-freeipa/.ansible-lint.
INFO     Set ANSIBLE_LIBRARY=/home/rjeffman/.cache/ansible-compat/c37ee1/modules:plugins/modules:/home/rjeffman/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/home/rjeffman/.cache/ansible-compat/c37ee1/collections:/home/rjeffman/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/home/rjeffman/.cache/ansible-compat/c37ee1/roles:roles:/home/rjeffman/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
INFO     Set ANSIBLE_LIBRARY=/home/rjeffman/.cache/ansible-compat/c37ee1/modules:plugins/modules:/home/rjeffman/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/home/rjeffman/.cache/ansible-compat/c37ee1/collections:/home/rjeffman/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/home/rjeffman/.cache/ansible-compat/c37ee1/roles:roles:/home/rjeffman/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
INFO     Executing syntax check on playbook tests/group/test_groups_present_slice.yml (0.29s)
Traceback (most recent call last):
  File "/tmp/freeipa/bin/ansible-lint", line 8, in <module>
    sys.exit(_run_cli_entrypoint())
             ^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/freeipa/lib64/python3.11/site-packages/ansiblelint/__main__.py", line 391, in _run_cli_entrypoint
    sys.exit(main(sys.argv))
             ^^^^^^^^^^^^^^
  File "/tmp/freeipa/lib64/python3.11/site-packages/ansiblelint/__main__.py", line 351, in main
    result = get_matches(rules, options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/freeipa/lib64/python3.11/site-packages/ansiblelint/runner.py", line 654, in get_matches
    matches.extend(runner.run())
                   ^^^^^^^^^^^^
  File "/tmp/freeipa/lib64/python3.11/site-packages/ansiblelint/runner.py", line 179, in run
    rule=self.rules["warning"],
         ~~~~~~~~~~^^^^^^^^^^^
  File "/tmp/freeipa/lib64/python3.11/site-packages/ansiblelint/rules/__init__.py", line 461, in __getitem__
    raise ValueError(msg)
ValueError: Rule warning is not present inside this collection.
audgirka commented 1 year ago

@rjeffman I'm able to see the desired output, when trying to reproduce the issue from ansible-lint main branch.

Screenshot 2023-10-19 at 13 55 13
audgirka commented 1 year ago

I did try with the command you mentioned: ansible-lint --offline --profile production --parseable --force-color tests/group/test_groups_present_slice.yml and now I'm able to reproduce the issue.

ansible-lint uses production profile by default, so no need to pass it explicitly.

When I remove the --profile argument it works: ansible-lint --offline --parseable --force-color tests/group/test_groups_present_slice.yml

Will try to look into the profile argument issue

rjeffman commented 1 year ago

Thank you for the workaround and for looking into this.