Comments (4)
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 JinjaStringModel
IMO doesn't help that much with the analysis, as it is a subtype of all types. That is, ignore_errors
needs to accept bool | JinjaStringModel
, and retries needs to accept int | JinjaStringModel
, so a JinjaStringModel
can be used almost anywhere, and doesn't really convey type information. Worse, it's a "valid" value regardless of the type that the JinjaStringModel
actually returns. We could have a Generic form of the type (something like int | JinjaExpr<int>
). But now we have the problem of knowing the return type of a Jinja expression. And if we already have that, we don't really need yaml schema validation; we can just raise that validation from whatever is determining the type of the Jinja expressions.
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 set_fact: { "x": 5 }
instead of us storing {"x": 5}
, we store {"x": int}
.
from vscode-ansible.
Another problem link to that kind of definition:
When this is use in a tasks
, pre_tasks
or post_tasks
of a playbook, like:
- hosts: all
gather_facts: False
pre_tasks:
- name: test
fail:
msg: test
ignore_errors: "{{ ansible_check_mode | bool }}"
roles:
- test
This show two errors:
- the type of
ignore_errors
, like said previously, - one on the task level:
Missing property "action".yaml-schema: BeremothTaskModel
. The error is not present whenignore_errors
is define bytrue
orfalse
.
from vscode-ansible.
Indeed that is a real issue because if we enable use of str
in addition to bool
it will fail to identify real bugs like plain strings.
My guess is that we should create a JinjaStringModel
which would only allow strings that are jinja2 constructs, basically requiring something like {.*}
as jinja could have {#
, {%
and {{
.
Does anyone have a better idea?
from vscode-ansible.
Closing this because the codebase changed completely since the bug was reported. We no longer use YAML/JSON schemas to validate these files.
from vscode-ansible.
Related Issues (20)
- Add document formatting feature OR set YAML extension's formatter on ansible playbooks. HOT 2
- Adopt ansible-language-server into vscode-ansible repository HOT 2
- Suggestions show all installed collections as part of 'ansible.builtin' HOT 1
- Improve Ansible LSP Docs for Vim and Neovim
- RFE: Allow for right-click on a molecule scenario to run it
- chore: upgrade chai v5
- Scaffolding collection fails when the web view in used for subsequent usage
- aaa HOT 1
- ansible variable resolution with live preview HOT 1
- Code quality checklist
- easily follow imports
- Modules from collections are not recognized when COLLECTIONS_PATH is set via env var HOT 1
- Standardise the functionalities provided by ansible-creator in the extension
- Ansible-language-server npm package 1.2.2 is missing core files HOT 1
- RFE: Ability to add devcontainer/devfile files to a workspace w/o ansible-creator
- Update development documentation for the new project structure
- "Open collection" should open in new window, with a new virtual environment
- Disable create buttons in the collection and project creation web-views during the scaffolding process
- Hung up remote session keeps running at 100% CPU HOT 3
- [error] Error: ENOENT: no such file or directory, stat - with temp pyc files
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vscode-ansible.