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 broken in VS Code with ansible-compat 25.1.0 and 25.0.0 #454

Closed
neilgoodman opened this issue Jan 28, 2025 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@neilgoodman
Copy link

Summary

ansible-compat 25.1.0 and 25.0.0 cause ansible-lint to throw an error within the Ansible 25.1.0 plugin in VS Code, breaking linting from within the editor:

Command failed: ansible-lint  --offline --nocolor -f codeclimate "~/src/ansible-compat-lint-vscode-bug/ansible/test_playbook.yaml"
Traceback (most recent call last):
  File "/usr/lib/python3.13/pathlib/_local.py", line 722, in mkdir
    os.mkdir(self, mode)
    ~~~~~~~~^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/.ansible/roles'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/bin/ansible-lint", line 8, in <module>
    sys.exit(_run_cli_entrypoint())
             ~~~~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3.13/site-packages/ansiblelint/__main__.py", line 408, in _run_cli_entrypoint
    sys.exit(main(sys.argv))
             ~~~~^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/ansiblelint/__main__.py", line 285, in main
    cache_dir_lock = initialize_options(argv[1:])
  File "/usr/lib/python3.13/site-packages/ansiblelint/__main__.py", line 139, in initialize_options
    options.cache_dir = get_cache_dir(pathlib.Path(options.project_dir))
                        ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/ansible_compat/prerun.py", line 27, in get_cache_dir
    (cache_dir / name).mkdir(parents=True, exist_ok=True)
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/pathlib/_local.py", line 726, in mkdir
    self.parent.mkdir(parents=True, exist_ok=True)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/pathlib/_local.py", line 722, in mkdir
    os.mkdir(self, mode)
    ~~~~~~~~^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '/.ansible'
Issue Type
  • Bug Report
OS / ENVIRONMENT

I am on Arch Linux:

uname -r
6.12.10-arch1-1

I'm using VS Code 1.96.4 and Ansible plugin v25.1.0

python -c "import ansible_compat; print(ansible_compat.__version__)"
25.1.0
  • ansible installation method: OS package
  • ansible-compat installation method: OS package
STEPS TO REPRODUCE
  1. Clone my minimal test case repro here: https://github.com/neilgoodman/ansible-compat-lint-vscode-bug
  2. Install VS Code 1.96.4
  3. Open .vscode/ansible-compat-lint-vscode-bug.code-workspace
  4. Install the workspace recommended Ansible plugin (version v25.1.0)
  5. Open the ansible/test_playbook.yaml file and the error message should popup
  6. Install ansible-compat 24.10.0, follow steps 1-4, error message doesn't popup and the file should highlight a linting issue
Desired Behavior

For linting to work within VS Code as it did with 24.10.0

Actual Behavior

Linting breaks with the above error within VS Code and ansible-compat 25.1.0

minimum complete verifiable example

@audgirka
Copy link
Contributor

@neilgoodman The latest release of ansible-compat fixes this issue

@skrysmanski
Copy link

@audgirka

The latest release of ansible-compat fixes this issue

Which version is this exactly? I still have the problem with 25.1.1 and this seems to be the latest version.

@neilgoodman
Copy link
Author

I just installed the main branch for the package and I now get this error in VS Code:

Command failed: ansible-lint  --offline --nocolor -f codeclimate "/home/ngood/src/ansible-compat-lint-vscode-bug/ansible/test_playbook.yaml"
Failed to create cache directory.

I don't believe this issue is resolved. I'll try running git bisect now that I have the git repo installed locally.

@neilgoodman
Copy link
Author

I ran git bisect between tag v25.1.1 and v24.10.0 and got this as a candidate for the broken commit: 29d0329

To be clear, that is for the issue that causes the exception message in the original bug report.

Given the subject of that commit, is it possible the issue now is related to #455?

@skrysmanski
Copy link

At some point when I was running into this issue, I got the Ansbile VSCode extension to spit out the full traceback (not sure how and it doesn't do it anymore):

Path for lint: /usr/local/bin/ansible-lint
Validating using ansible-lint
[Info  - 1:27:05 PM] [ansible-lint] Traceback (most recent call last):
  File "/usr/local/lib/python3.13/pathlib/_local.py", line 722, in mkdir
    os.mkdir(self, mode)
    ~~~~~~~~^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/.ansible/roles'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/ansible-lint", line 8, in <module>
    sys.exit(_run_cli_entrypoint())
             ~~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/site-packages/ansiblelint/__main__.py", line 408, in _run_cli_entrypoint
    sys.exit(main(sys.argv))
             ~~~~^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/ansiblelint/__main__.py", line 285, in main
    cache_dir_lock = initialize_options(argv[1:])
  File "/usr/local/lib/python3.13/site-packages/ansiblelint/__main__.py", line 139, in initialize_options
    options.cache_dir = get_cache_dir(pathlib.Path(options.project_dir))
                        ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/ansible_compat/prerun.py", line 27, in get_cache_dir
    (cache_dir / name).mkdir(parents=True, exist_ok=True)
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/pathlib/_local.py", line 726, in mkdir
    self.parent.mkdir(parents=True, exist_ok=True)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/pathlib/_local.py", line 722, in mkdir
    os.mkdir(self, mode)
    ~~~~~~~~^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '/usr/local/.ansible'

cmd 'ansible-lint --version' was not executed with the following error: ' Command failed: ansible-lint --version
Traceback (most recent call last):
  File "/usr/local/lib/python3.13/pathlib/_local.py", line 722, in mkdir
    os.mkdir(self, mode)
    ~~~~~~~~^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/.ansible/roles'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/ansible-lint", line 8, in <module>
    sys.exit(_run_cli_entrypoint())
             ~~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/site-packages/ansiblelint/__main__.py", line 408, in _run_cli_entrypoint
    sys.exit(main(sys.argv))
             ~~~~^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/ansiblelint/__main__.py", line 285, in main
    cache_dir_lock = initialize_options(argv[1:])
  File "/usr/local/lib/python3.13/site-packages/ansiblelint/__main__.py", line 139, in initialize_options
    options.cache_dir = get_cache_dir(pathlib.Path(options.project_dir))
                        ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/ansible_compat/prerun.py", line 27, in get_cache_dir
    (cache_dir / name).mkdir(parents=True, exist_ok=True)
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/pathlib/_local.py", line 726, in mkdir
    self.parent.mkdir(parents=True, exist_ok=True)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/pathlib/_local.py", line 722, in mkdir
    os.mkdir(self, mode)
    ~~~~~~~~^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '/usr/local/.ansible'

I'm no Python developer but the problematic line seems to be this:

options.cache_dir = get_cache_dir(pathlib.Path(options.project_dir))

I'm not sure how options.project_dir is populated but it could the current working directory (which - in my case - seems to be /usr/local).

From the traceback I seems I'm not using a virtual env, so I'm getting into the elif isolated: branch.

From the traceback it also seems that isolated is always true here which is why the else branch - which uses os.environ.get("ANSIBLE_HOME", "~/.ansible") - is never used.

Side note: The fix that @audgirka talked about is most likely 2a8732f. Strangely, this commit also removed the else branch completely (without mentioning this in the commit message) - is this a bug?

In any case, these changes seem to completely drop the use of ~./ansible as cache directory without giving the user an option to get the old behavior back (again, not sure if this change was intentional).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

3 participants