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

Minimum ansible version check fails with stack dump #1378

Closed
JohnMalmberg opened this issue Feb 18, 2021 · 3 comments · Fixed by #1381 or #1383
Closed

Minimum ansible version check fails with stack dump #1378

JohnMalmberg opened this issue Feb 18, 2021 · 3 comments · Fixed by #1381 or #1383
Assignees
Labels

Comments

@JohnMalmberg
Copy link

Summary

See https://github.com/ansible-community/ansible-lint/blob/master/src/ansiblelint/_prerun.py

The "failed" check block at line 45 is referencing the variable "version" which only exists if the except block is thrown.
If the version compare fails this causes a pretty much useless stack trace instead of explaining the version issue.

The version check is also using "<=" instead of "<" for the check, which means that the version set for "ANSIBLE_MIN_VERSION" is not the actual minimum version that will work with the linting program.

This bug appears to have been introduced with ansible-lint 5.0.0.

Issue Type
  • Bug Report
Ansible and Ansible Lint details
$ ansible --version
ansible 2.9.0
$ ansible-lint --version
ansible-lint 5.0.1
See trace back below,
  • ansible installation method: one of source, pip
  • ansible-lint installation method: one of source, pip
OS / ENVIRONMENT

Run in a virtualenv on CentOS 7.9

STEPS TO REPRODUCE

ansible-lint --version

ansible-lint --version
Desired Behaviour

ansible-lint --version
ansible-lint 5.0.1

Possible security bugs should be reported via email to security@ansible.com

Actual Behaviour

Please give some details of what is actually happening.
Include a [minimum complete verifiable example] with:

  • playbook
  • output of running ansible-lint
  • if you're getting a stack trace, output of
    ansible-playbook --syntax-check playbook
$ ansible-lint --version
ansible-lint 5.0.1
Traceback (most recent call last):
  File "/home/mypath/roles/test_venv/bin/ansible-lint", line 8, in <module>
    sys.exit(_run_cli_entrypoint())
  File "/home/mypath/roles/test_venv/lib64/python3.6/site-packages/ansiblelint/__main__.py", line 254, in _run_cli_entrypoint
    sys.exit(main(sys.argv))
  File "/home/mypath/roles/test_venv/lib64/python3.6/site-packages/ansiblelint/__main__.py", line 155, in main
    initialize_options(argv[1:])
  File "/home/mypath/ansible-lab/roles/test_venv/lib64/python3.6/site-packages/ansiblelint/__main__.py", line 80, in initialize_options
    check_ansible_presence()
  File "/home/mypath/ansible-lab/roles/test_venv/lib64/python3.6/site-packages/ansiblelint/_prerun.py", line 52, in check_ansible_presence
    % (ANSIBLE_MIN_VERSION, __version__),
UnboundLocalError: local variable '__version__' referenced before assignment

@JohnMalmberg
Copy link
Author

This does not appear to fix the crash at all.

The undefined variable reference is in the block after the except clause that was modified by the patch at line 52 in the "if failed:" block.

So Improve ansible version check #1381 effectively does nothing.

It also does not address that the constant name implies that it is the minimum version that is expected to supported, yet the way the check is done by using "<=" instead of "<" will result in that version ansible being blocked from using it.

@ssbarnea ssbarnea self-assigned this Feb 19, 2021
@ssbarnea
Copy link
Member

Thanks! Reopening now and also rewriting the check as I plan to cover a quite common issue where ansible executable is using a different version of ansible module, something that is very likely to cause confusions and hard to debug issues with the linter. Once done, it will check that both report the same version.

@ssbarnea ssbarnea reopened this Feb 19, 2021
ssbarnea added a commit that referenced this issue Feb 19, 2021
- assure we check that ansible python module and ansible cli versions
  are the same
- print ansible version alongside ansible-lint version
- fix version version comparison from <= to <

Fixes: #1378
@ssbarnea
Copy link
Member

@JohnMalmberg please review/test the pull-request above, I hope that follow-up sorts the issue for good.

ssbarnea added a commit that referenced this issue Feb 19, 2021
- assure we check that ansible python module and ansible cli versions
  are the same
- print ansible version alongside ansible-lint version
- fix version version comparison from <= to <

Fixes: #1378
ssbarnea added a commit that referenced this issue Feb 19, 2021
- assure we check that ansible python module and ansible cli versions
  are the same
- print ansible version alongside ansible-lint version
- fix version version comparison from <= to <

Fixes: #1378
ssbarnea added a commit that referenced this issue Feb 20, 2021
- assure we check that ansible python module and ansible cli versions
  are the same
- print ansible version alongside ansible-lint version
- fix version version comparison from <= to <

Fixes: #1378
ssbarnea added a commit that referenced this issue Feb 20, 2021
- assure we check that ansible python module and ansible cli versions
  are the same
- print ansible version alongside ansible-lint version
- fix version version comparison from <= to <

Fixes: #1378
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants