-
Notifications
You must be signed in to change notification settings - Fork 81
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
Can't use variable when schema define something as boolean #125
Comments
Another problem link to that kind of definition:
This show two errors:
|
Indeed that is a real issue because if we enable use of My guess is that we should create a Does anyone have a better idea? |
I can't reproduce this working off of source ( ansible-language-server 71d759d, vscode-ansible 5ef7df7 ) or from the latest from the marketplace. I tried looking through the schema definitions, but I didn't find where we forced this to be a boolean. I thought it was possible that this error was coming from the YAML vscode extension, but that didn't reproduce it either. For resolving the underlying desired result (analysing the type of the Jjinja return and validating that), ansible+jinja is too powerful for simple schema verification to properly analyse. Adding a It turns out that It's not too hard to inspect a Jinja AST: >>> jinja2.Environment().parse("{{ true }}")
Template(body=[Output(nodes=[Const(value=True)])])
>>> jinja2.Environment().parse("{{ ansible_check_mode }}")
Template(body=[Output(nodes=[Name(name='ansible_check_mode', ctx='load')])]) We could then look up the symbol in a table of symbols which would be defined at that scope. We might be able to share some of that code with Ansible itself. Although I suspect some refactoring would be necessary, as we're interested more in the provenance and type of variables than their values. One easy (ish) trick to do type validations is to traverse the program, but instead of keeping track of values in assignments we keep track of their types. For example, if we had |
Closing this because the codebase changed completely since the bug was reported. We no longer use YAML/JSON schemas to validate these files. |
Co-authored-by: Sviatoslav Sydorenko <wk@sydorenko.org.ua>
Describe the bug
When something is define as boolean in the schema, like
ignore_errors
when the value is set by a variable, vscode show an error tellingIncorrect type. Expected "boolean".yaml-schema: BeremothTaskModel
, even with the filterbool
to force the type of the variable.To Reproduce
Create a task like:
Expected behavior
No error about the type, at least when the type is forced (if
| bool
is specified this trigger a warning in the default configuration of ansible-lint, not without, so it'll be better if this isn't needed).Platform:
Be sure vscode and extension are the latest versions and report here the
operating system you used. If you used remote-ssh or WSL. Please check if the
bug can be reproduced on Linux or MacOS.
The text was updated successfully, but these errors were encountered: