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

Exception when running ansible-lint --version #2633

Closed
Histalek opened this issue Oct 29, 2022 · 3 comments · Fixed by #2641
Closed

Exception when running ansible-lint --version #2633

Histalek opened this issue Oct 29, 2022 · 3 comments · Fixed by #2641
Labels

Comments

@Histalek
Copy link

Summary

An exception occurs when running ansible-lint --version in a container with alpine edge based ansible-lint package.

I haven't tested the master branch yet, but if i read the one commit correctly it would only mask this issue for the first 24h after a release is done.

Issue Type
  • Bug Report
Ansible and Ansible Lint details
/ # ansible --version
ansible [core 2.13.5]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.10/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.8 (main, Oct 26 2022, 17:46:33) [GCC 12.2.1 20220924]
  jinja version = 3.1.2
  libyaml = True

/ # ansible-lint --version
Failed to locate command: [Errno 2] No such file or directory: 'git'
ansible-lint 6.8.4 using ansible 2.13.5
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/ansiblelint/config.py", line 227, in guess_install_method
    from pip._internal.exceptions import UninstallationError
ModuleNotFoundError: No module named 'pip'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/ansible-lint", line 8, in <module>
    sys.exit(_run_cli_entrypoint())
  File "/usr/lib/python3.10/site-packages/ansiblelint/__main__.py", line 317, in _run_cli_entrypoint
    sys.exit(main(sys.argv))
  File "/usr/lib/python3.10/site-packages/ansiblelint/__main__.py", line 190, in main
    console.print(get_version_warning())
  File "/usr/lib/python3.10/site-packages/ansiblelint/config.py", line 288, in get_version_warning
    pip = guess_install_method()
  File "/usr/lib/python3.10/site-packages/ansiblelint/config.py", line 239, in guess_install_method
    except (UninstallationError, AttributeError, ImportError) as exc:
UnboundLocalError: local variable 'UninstallationError' referenced before assignment
  • ansible installation method: OS package
  • ansible-lint installation method: OS package
OS / ENVIRONMENT

Alpine based container with packages from the alpine edge repository.
Pip is not installed.

STEPS TO REPRODUCE

instead of podman docker might be used or any other comparable oci container engine.

$ podman run --rm -it alpine:edge /bin/sh

/ # apk add ansible-lint py3-filelock
/ # ansible-lint --version
Desired Behavior

Running ansible-lint --version does not lead to an exception.

Actual Behavior

(-vvvv does not lead to extra output, used regardless)

/ # ansible-lint --version -vvvv
Failed to locate command: [Errno 2] No such file or directory: 'git'
ansible-lint 6.8.4 using ansible 2.13.5
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/ansiblelint/config.py", line 227, in guess_install_method
    from pip._internal.exceptions import UninstallationError
ModuleNotFoundError: No module named 'pip'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/ansible-lint", line 8, in <module>
    sys.exit(_run_cli_entrypoint())
  File "/usr/lib/python3.10/site-packages/ansiblelint/__main__.py", line 317, in _run_cli_entrypoint
    sys.exit(main(sys.argv))
  File "/usr/lib/python3.10/site-packages/ansiblelint/__main__.py", line 190, in main
    console.print(get_version_warning())
  File "/usr/lib/python3.10/site-packages/ansiblelint/config.py", line 288, in get_version_warning
    pip = guess_install_method()
  File "/usr/lib/python3.10/site-packages/ansiblelint/config.py", line 239, in guess_install_method
    except (UninstallationError, AttributeError, ImportError) as exc:
UnboundLocalError: local variable 'UninstallationError' referenced before assignment
@Histalek Histalek added bug new Triage required labels Oct 29, 2022
@AKorezin
Copy link

This problem is introduced by #2624.

If the pip module is absent, then from pip._internal.exceptions import UninstallationError will throw an ImportError exception, and UninstallationError will not be available.

@ssbarnea ssbarnea removed the new Triage required label Oct 31, 2022
@ssbarnea
Copy link
Member

Fixed on main branch, a new release will be out today.

@AKorezin
Copy link

AKorezin commented Oct 31, 2022

Hi @ssbarnea,
It's not fixed.
I've rebuilt 8c8d9a3 with SETUPTOOLS_SCM_PRETEND_VERSION=6.8.3 and got this error.

Let's imagine you will release new changes in 6.8.5.
If the upstream version is 6.8.6, it will trigger

elif current_version < new_version:
msg = f"""[warning]A new release of ansible-lint is available: [red]{current_version}[/] → [green][link={html_url}]{new_version}[/][/][/]"""
pip = guess_install_method()
.

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.

3 participants