-
Notifications
You must be signed in to change notification settings - Fork 664
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
Permission denied: '/.config/ansible-lint.yml'
when no config file exists and executed outside of a project
#4306
Comments
@C0rn3j You failed to mention a critical piece of information: what is the current directory in which you did run the linter. If you run linter at Still, I suspect that you face this in another case and I am quite curious to find a way to reproduce it, so we can fix it well. |
Home of my user. Now that you mention that, I can see I easily repro this by simply adding the hack, verifying it works them cd'ing from $HOME to /tmp and it breaks again. irrelevant now[130] % ansible-lint --version
ansible-lint 24.9.3.dev0 using ansible-core:2.17.4 ansible-compat:24.9.1 ruamel-yaml:0.18.6 ruamel-yaml-clib:0.2.8
[0] % cd /tmp
[0] % ansible-lint --version
Traceback (most recent call last):
File "/usr/bin/ansible-lint", line 8, in <module>
sys.exit(_run_cli_entrypoint())
^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/ansiblelint/__main__.py", line 411, in _run_cli_entrypoint
sys.exit(main(sys.argv))
^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/ansiblelint/__main__.py", line 290, in main
cache_dir_lock = initialize_options(argv[1:])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/ansiblelint/__main__.py", line 125, in initialize_options
new_options = cli.get_config(arguments or [])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/ansiblelint/cli.py", line 606, in get_config
project_dir, method = find_project_root(
^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/ansiblelint/file_utils.py", line 526, in find_project_root
if resolved_cfg_path.is_file():
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/pathlib.py", line 892, in is_file
return S_ISREG(self.stat().st_mode)
^^^^^^^^^^^
File "/usr/lib/python3.12/pathlib.py", line 840, in stat
return os.stat(self, follow_symlinks=follow_symlinks)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '/.config/ansible-lint.yml' EDIT 1: It seems to simply resolve upwards all the way til it hits / and tries to read a file it does not have permissions for? # cwd /usr/lib/python3.12/site-packages/ansiblelint
[0] % ansible-lint --version
# find_project_root() in file_utils.py
directory: /usr/lib/python3.12/site-packages/ansiblelint; of type <class 'pathlib.PosixPath'>
resolved_cfg_path: /usr/lib/python3.12/site-packages/ansiblelint; of type <class 'pathlib.PosixPath'> / cfg_file: .ansible-lint of type <class 'str'>
resolved_cfg_path: /usr/lib/python3.12/site-packages/ansiblelint; of type <class 'pathlib.PosixPath'> / cfg_file: .config/ansible-lint.yml of type <class 'str'>
resolved_cfg_path: /usr/lib/python3.12/site-packages/ansiblelint; of type <class 'pathlib.PosixPath'> / cfg_file: .config/ansible-lint.yaml of type <class 'str'>
directory: /usr/lib/python3.12/site-packages; of type <class 'pathlib.PosixPath'>
resolved_cfg_path: /usr/lib/python3.12/site-packages; of type <class 'pathlib.PosixPath'> / cfg_file: .ansible-lint of type <class 'str'>
resolved_cfg_path: /usr/lib/python3.12/site-packages; of type <class 'pathlib.PosixPath'> / cfg_file: .config/ansible-lint.yml of type <class 'str'>
resolved_cfg_path: /usr/lib/python3.12/site-packages; of type <class 'pathlib.PosixPath'> / cfg_file: .config/ansible-lint.yaml of type <class 'str'>
directory: /usr/lib/python3.12; of type <class 'pathlib.PosixPath'>
resolved_cfg_path: /usr/lib/python3.12; of type <class 'pathlib.PosixPath'> / cfg_file: .ansible-lint of type <class 'str'>
resolved_cfg_path: /usr/lib/python3.12; of type <class 'pathlib.PosixPath'> / cfg_file: .config/ansible-lint.yml of type <class 'str'>
resolved_cfg_path: /usr/lib/python3.12; of type <class 'pathlib.PosixPath'> / cfg_file: .config/ansible-lint.yaml of type <class 'str'>
directory: /usr/lib; of type <class 'pathlib.PosixPath'>
resolved_cfg_path: /usr/lib; of type <class 'pathlib.PosixPath'> / cfg_file: .ansible-lint of type <class 'str'>
resolved_cfg_path: /usr/lib; of type <class 'pathlib.PosixPath'> / cfg_file: .config/ansible-lint.yml of type <class 'str'>
resolved_cfg_path: /usr/lib; of type <class 'pathlib.PosixPath'> / cfg_file: .config/ansible-lint.yaml of type <class 'str'>
directory: /usr; of type <class 'pathlib.PosixPath'>
resolved_cfg_path: /usr; of type <class 'pathlib.PosixPath'> / cfg_file: .ansible-lint of type <class 'str'>
resolved_cfg_path: /usr; of type <class 'pathlib.PosixPath'> / cfg_file: .config/ansible-lint.yml of type <class 'str'>
resolved_cfg_path: /usr; of type <class 'pathlib.PosixPath'> / cfg_file: .config/ansible-lint.yaml of type <class 'str'>
directory: /; of type <class 'pathlib.PosixPath'>
resolved_cfg_path: /; of type <class 'pathlib.PosixPath'> / cfg_file: .ansible-lint of type <class 'str'>
resolved_cfg_path: /; of type <class 'pathlib.PosixPath'> / cfg_file: .config/ansible-lint.yml of type <class 'str'>
Traceback (most recent call last):
...
PermissionError: [Errno 13] Permission denied: '/.config/ansible-lint.yml' EDIT: Here's the problem, I have a legitimate
EDIT2: for directory in (common_base, *common_base.parents):
# print(f'directory: {directory}; of type {type(directory)}')
if directory is None:
exit(125)
if (directory / ".git").exists():
return directory, ".git directory"
if (directory / ".hg").is_dir():
return directory, ".hg directory"
for cfg_file in cfg_files:
# note that if cfg_file is already absolute, 'directory' is ignored
resolved_cfg_path = directory / cfg_file
# print(f'resolved_cfg_path: {directory}; of type {type(directory)} / cfg_file: {cfg_file} of type {type(cfg_file)}')
try:
if resolved_cfg_path.is_file():
if os.path.isabs(cfg_file):
directory = Path(cfg_file).parent
if directory.name == ".config":
directory = directory.parent
return directory, f"config file {resolved_cfg_path}"
except PermissionError:
print(f"Permission error trying to read {resolved_cfg_path}") aand third email is the charm, this nets me:
Unsure what's the proper fix, but catching exceptions at least allows the code to run with warnings. Code here - ansible-lint/src/ansiblelint/file_utils.py Lines 516 to 532 in 3b5bee1
|
I am afraid that we will not want to ignore a permission denied error, so a fix would only remove the stack trace without allowing the linter to run. -- that is for genuine reasons, as we do not want to give false positives when linter is unable to access files. |
I do not think it should be removed, but it should indeed be handled and logged at minimum. As long as the user won't need to spend an hour debugging to figure out why it randomly crashes, I think it's a good thing. Am not sure if I even need the /.config folder, it probably got created on accident. |
Continuing to move this along, I think it would be worth at least covering the stack trace with a more digestible message. I like your suggestions @C0rn3j, but I would probably use something like |
Summary
I have originally reported this issue downstream in the Ansible VSC extension, but it seems it's an issue in ansible-lint.
Issue Type
OS / ENVIRONMENT
Running on Arch Linux from the repo packages:
STEPS TO REPRODUCE
Execute
ansible-lint
in home folder. even--version
fails.Desired Behavior
No error.
Actual Behavior
Error.
The text was updated successfully, but these errors were encountered: