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 crashes if it is not run from the git repository #1674

Closed
tadeboro opened this issue Jul 17, 2021 · 2 comments · Fixed by #1675
Closed

Ansible Lint crashes if it is not run from the git repository #1674

tadeboro opened this issue Jul 17, 2021 · 2 comments · Fixed by #1675
Assignees
Labels

Comments

@tadeboro
Copy link
Contributor

Summary

Running ansible-lint --version from anywhere but a git repository results in a crash with a stacktrace.

Issue Type
  • Bug Report
Ansible and Ansible Lint details

Ansible Lint version: 5.1.1 (cannot paste --version output because the program crashes).

  • ansible-lint installation method: one of pip, OS package
OS / ENVIRONMENT
STEPS TO REPRODUCE

Run ansible-lint --version from the /tmp folder, for example.

$ ansible-lint --version
Traceback (most recent call last):
  File "/home/tadej/tmp/venv/bin/ansible-lint", line 33, in <module>
    sys.exit(load_entry_point('ansible-lint', 'console_scripts', 'ansible-lint')())
  File "/home/tadej/xlab/ansible/ansible-lint/src/ansiblelint/__main__.py", line 299, in _run_cli_entrypoint
    sys.exit(main(sys.argv))
  File "/home/tadej/xlab/ansible/ansible-lint/src/ansiblelint/__main__.py", line 196, in main
    initialize_options(argv[1:])
  File "/home/tadej/xlab/ansible/ansible-lint/src/ansiblelint/__main__.py", line 83, in initialize_options
    new_options = cli.get_config(arguments or [])
  File "/home/tadej/xlab/ansible/ansible-lint/src/ansiblelint/cli.py", line 385, in get_config
    project_dir = guess_project_dir(options.config_file)
  File "/home/tadej/xlab/ansible/ansible-lint/src/ansiblelint/file_utils.py", line 273, in guess_project_dir
    path = result.stdout.splitlines()[0]
IndexError: list index out of range
Desired Behaviour

Ansible Lint should print out its version number.

Additional information

git blame reported #1661 as the source of the breakage. It was a bit tricky to find the real cause because that one commit contains a bunch of refactoring alongside the actual fix. The error was introduced in https://github.com/ansible-community/ansible-lint/pull/1661/files#diff-4525388e8f05ebb145c2c2366127aba4f3716da965f32a91b70b5c4a0eafd35aL268-L269 because now we do not check the exit code of the git command anymore.

Originally reported by Amin.

@tadeboro tadeboro added new Triage required bug labels Jul 17, 2021
@tadeboro
Copy link
Contributor Author

/cc @xabinapal Just for reference.

@ssbarnea ssbarnea self-assigned this Jul 17, 2021
@ssbarnea
Copy link
Member

Found it myself few minutes ago and already got a fix, but now I am writing tests to prevent future regressions.

ssbarnea added a commit that referenced this issue Jul 17, 2021
@ssbarnea ssbarnea removed the new Triage required label Jul 17, 2021
ssbarnea added a commit that referenced this issue Jul 17, 2021
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