Giter VIP home page Giter VIP logo

Comments (4)

lilatomic avatar lilatomic commented on May 25, 2024 1

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.

RomainMou avatar RomainMou commented on May 25, 2024

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 when ignore_errors is define by true or false.

from vscode-ansible.

ssbarnea avatar ssbarnea commented on May 25, 2024

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.

ssbarnea avatar ssbarnea commented on May 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.