vscode-ansible
vscode-ansible copied to clipboard
Diagnostics using ansible-lint not working as expected
Summary
If running ansible-lint on playbook results in an error it fallback to ansible syntax check. The expected behaviour is the error from running ansible-lint should be displayed to the user instead of syntax check fallback
Note: when running ansible-lint from command-line on the same playbook the output is
% ansible-lint --offline --nocolor -f codeclimate "/Users/ganeshrn/Documents/ansible-collections/eos_config_diff.yaml"
Failed to guess project directory using git:
WARNING Overriding detected file kind 'yaml' with 'playbook' for given positional argument: /Users/ganeshrn/Documents/ansible-collections/eos_config_diff.yaml
INFO Executing syntax check on eos_config_diff.yaml (0.67s)
[{"type": "issue", "check_name": "[yaml] truthy value should be one of [false, true]", "categories": ["formatting", "yaml"], "severity": "info", "description": "Rule violations reported by YamlLint when this is installed.\n\nYou can fully disable all of them by adding 'yaml' to the 'skip_list'.\n\nSpecific tag identifiers that are printed at the end of rule name,\nlike 'trailing-spaces' or 'indentation' can also be be skipped, allowing\nyou to have a more fine control.\n\nBy default this rule is not used when yamllint library is missing. If you want\nto make its absence a runtime failure, please add 'yaml' to 'enable_list'\ninside the configuration file.\n", "fingerprint": "8d09b5891f73d90f3c62a7d5f19c4d4b36a60f96d66697b0a34a3c9d9d0c3008", "location": {"path": "eos_config_diff.yaml", "lines": {"begin": 2}}}, {"type": "issue", "check_name": "[yaml] truthy value should be one of [false, true]", "categories": ["formatting", "yaml"], "severity": "info", "description": "Rule violations reported by YamlLint when this is installed.\n\nYou can fully disable all of them by adding 'yaml' to the 'skip_list'.\n\nSpecific tag identifiers that are printed at the end of rule name,\nlike 'trailing-spaces' or 'indentation' can also be be skipped, allowing\nyou to have a more fine control.\n\nBy default this rule is not used when yamllint library is missing. If you want\nto make its absence a runtime failure, please add 'yaml' to 'enable_list'\ninside the configuration file.\n", "fingerprint": "73cda576d0d442c3bead028520b473cbfbc3209bbd4df3787711f2e194499582", "location": {"path": "eos_config_diff.yaml", "lines": {"begin": 9}}}]
You can skip specific rules or tags by adding them to your configuration file:
# .ansible-lint
warn_list: # or 'skip_list' to silence them completely
- yaml # Violations reported by yamllint
Finished with 2 failure(s), 0 warning(s) on 1 files.
Extension version
0.5.1
VS Code version
1.61.4
Ansible Version
ansible --version
ansible [core 2.11.6]
config file = /Users/ganeshrn/Documents/ansible-collections/ansible.cfg
configured module search path = ['/Users/ganeshrn/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/ganeshrn/Documents/ansible-collections/.env/lib/python3.8/site-packages/ansible
ansible collection location = /Users/ganeshrn/.ansible/collections:/usr/share/ansible/collections
executable location = /Users/ganeshrn/Documents/ansible-collections/.env/bin/ansible
python version = 3.8.2 (default, Apr 8 2021, 23:19:18) [Clang 12.0.5 (clang-1205.0.22.9)]
jinja version = 2.11.3
libyaml = True
OS / Environment
Mac OS
Relevant log output
No response
More ansible-server logs from the output console
Ansible-lint command execution failed. Falling back to ansible syntax-check
Validating using ansible syntax-check
[Trace - 10:45:08 AM] Received request 'window/showMessageRequest - (28)'.
Params: {
"type": 1,
"message": "Command failed: /Users/ganeshrn/Documents/ansible-collections/.env/bin/ansible-lint --offline --nocolor -f codeclimate \"/Users/ganeshrn/Documents/ansible-collections/vyos_config_diff.yaml\"\nTraceback (most recent call last):\n File \"/Users/ganeshrn/Documents/ansible-collections/.env/bin/ansible-lint\", line 5, in <module>\n from ansiblelint.__main__ import _run_cli_entrypoint\n File \"/Users/ganeshrn/Documents/ansible-collections/.env/lib/python3.8/site-packages/ansiblelint/__main__.py\", line 36, in <module>\n from ansiblelint import cli\n File \"/Users/ganeshrn/Documents/ansible-collections/.env/lib/python3.8/site-packages/ansiblelint/cli.py\", line 13, in <module>\n from ansiblelint.config import DEFAULT_KINDS\n File \"/Users/ganeshrn/Documents/ansible-collections/.env/lib/python3.8/site-packages/ansiblelint/config.py\", line 167, in <module>\n if ansible_collections_path() in os.environ:\n File \"/Users/ganeshrn/Documents/ansible-collections/.env/lib/python3.8/site-packages/ansiblelint/config.py\", line 117, in ansible_collections_path\n if ansible_version() >= ansible_version(\"2.10.0.dev0\"):\n File \"/Users/ganeshrn/Documents/ansible-collections/.env/lib/python3.8/site-packages/ansiblelint/config.py\", line 146, in ansible_version\n proc = subprocess.run(\n File \"/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py\", line 489, in run\n with Popen(*popenargs, **kwargs) as process:\n File \"/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py\", line 854, in __init__\n self._execute_child(args, executable, preexec_fn, close_fds,\n File \"/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py\", line 1702, in _execute_child\n raise child_exception_type(errno_num, err_msg, err_filename)\nFileNotFoundError: [Errno 2] No such file or directory: 'ansible'\n",
"actions": []
}
is playbook...
.vscode/settings.json
{
"python.pythonPath": "/Users/ganeshrn/Documents/ansible-collections/.env/bin/python",
"ansible.ansible.useFullyQualifiedCollectionNames": true,
"ansible.ansible.path": "/Users/ganeshrn/Documents/ansible-collections/.env/bin/ansible",
"ansible.ansibleLint.path": "/Users/ganeshrn/Documents/ansible-collections/.env/bin/ansible-lint",
"ansible.executionEnvironment.enabled": false,
"ansibleServer.trace.server": "verbose",
}
I've made the traceback nicer
Command failed: /Users/ganeshrn/Documents/ansible-collections/.env/bin/ansible-lint --offline --nocolor -f codeclimate "/Users/ganeshrn/Documents/ansible-collections/vyos_config_diff.yaml"
Traceback (most recent call last):
File "/Users/ganeshrn/Documents/ansible-collections/.env/bin/ansible-lint", line 5, in <module>
from ansiblelint.__main__ import _run_cli_entrypoint
File "/Users/ganeshrn/Documents/ansible-collections/.env/lib/python3.8/site-packages/ansiblelint/__main__.py", line 36, in <module>
from ansiblelint import cli
File "/Users/ganeshrn/Documents/ansible-collections/.env/lib/python3.8/site-packages/ansiblelint/cli.py", line 13, in <module>
from ansiblelint.config import DEFAULT_KINDS
File "/Users/ganeshrn/Documents/ansible-collections/.env/lib/python3.8/site-packages/ansiblelint/config.py", line 167, in <module>
if ansible_collections_path() in os.environ:
File "/Users/ganeshrn/Documents/ansible-collections/.env/lib/python3.8/site-packages/ansiblelint/config.py", line 117, in ansible_collections_path
if ansible_version() >= ansible_version("2.10.0.dev0"):
File "/Users/ganeshrn/Documents/ansible-collections/.env/lib/python3.8/site-packages/ansiblelint/config.py", line 146, in ansible_version
proc = subprocess.run(
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py", line 489, in run
with Popen(*popenargs, **kwargs) as process:
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py", line 1702, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'ansible'
Possible upstream bug: https://github.com/ansible-community/ansible-lint/issues/1507.
Specific comment with the same traceback: https://github.com/ansible-community/ansible-lint/issues/1507#issuecomment-892522157.
I believe this was an ansible-lint bug which is fixed now.