Skip to content
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

Wrong yaml schema for group_vars? #36

Closed
tsia opened this issue Mar 3, 2021 · 11 comments
Closed

Wrong yaml schema for group_vars? #36

tsia opened this issue Mar 3, 2021 · 11 comments
Assignees
Labels
bug Something isn't working

Comments

@tsia
Copy link

tsia commented Mar 3, 2021

i have opened a Folder containing a playbook in vscode.
inside a subfolder named group_vars i have all.yml containing some variables.

vscode-ansible complains about the format because it uses the "Ansible Playbook Schema" for some reason:
image

i saw you have set yamlValidation accordingly in your package.json so i don't know what is happening here.

@ssbarnea
Copy link
Member

ssbarnea commented Mar 3, 2021

I have no idea why it gets confused as based on https://github.com/ansible-community/vscode-ansible/blob/master/package.json#L104-L115 it should pick the first pattern that matches, which is groups_vars. Do you happen to have these under a path that looks like playbooks/group_vars/all.yml ? -- is if you do, it would still have to work.

@ssbarnea ssbarnea added the bug Something isn't working label Mar 3, 2021
@tsia
Copy link
Author

tsia commented Mar 3, 2021

The group_vars folder actually is at the root of the project.

@ssbarnea ssbarnea self-assigned this Mar 4, 2021
@ssbarnea
Copy link
Member

ssbarnea commented Mar 4, 2021

I can confirm the bug, in fact it seems that whatever I do vars files seems to endup using the playbook schema. Looking at the config, I see no reason for this to happen.

The bug seems related to a recent merge made to redhat-developer/yaml-language-server#417 and I wonder if next release of YAML extension will adress it,... or make things even worse.

Test cases:

  • playbooks/all.yml - should use ansible-playbook schema
  • group_vars/all.yml - should use ansible-vars schema
  • playbooks/group_vars/all.yml - should use ansible-vars schema, even if both patterns are matching. I do think there is a real chance this may go wrong as I do remember that vscode original globbing was not very smart and a single * could expand to anything. I am also not sure if the order of the patterns is respected either. We do list playbooks at the end for good reasons: to avoid folders like vars/tasks/handlers nested inside playbooks/ to endup being recognized as playbooks.

I hope that @JPinkney or @joshuawilson may give us some insights here. Maybe the can help us by adding some extra tests that assure we can write patterns to distinguish between those cases.

@JPinkney
Copy link
Contributor

JPinkney commented Mar 4, 2021

I can probably take a look as to what's causing on the yaml side later today

@ssbarnea
Copy link
Member

ssbarnea commented Mar 4, 2021

I tested with vscode-ansible@master and I can confirm that now case 1 and 2 are now working (clear improvement), but 3 is not. playbooks/group_vars/all.yml is still identified as a playbook instead of a vars file and I do not know how to define patterns that avoid overlapping.

If you look at https://github.com/ansible-community/vscode-ansible/blob/master/package.json#L117 you will see that vars pattern is listed before the playbook one, so it should be picked first, right?

@JPinkney
Copy link
Contributor

JPinkney commented Mar 4, 2021

If you look at https://github.com/ansible-community/vscode-ansible/blob/master/package.json#L117 you will see that vars pattern is listed before the playbook one, so it should be picked first, right?

It evaluates everything equally, there is no way to prioritise one or the other. Let me try it with redhat-developer/yaml-language-server#417 and i'll see if that fixes it

@JPinkney
Copy link
Contributor

JPinkney commented Mar 4, 2021

I played around with playbooks/group_vars/all.yml and it looks like both schemas (vars and playbook) are currently being set. You can see this if you do:

allUsers
  aa

you'll see an error with:

Ansible Vars Schema

Incorrect type. Expected "ansible-vars.json".yaml-schema: Ansible Vars Schema
Incorrect type. Expected "array".yaml-schema: Ansible Playbook Schema

@bendem
Copy link

bendem commented Mar 15, 2021

I have a problem which I think might be related, if not I'll open another issue:
image
This is for a yaml file in ansible/playbooks/sso/tasks/openldap/.
I have the same problem with vars of all types (group_vars, host_vars, vars, defaults):
image

Basically, anything under playbooks/* is interpreted as a playbook, no matter the parent directory.

On that note, it might be cool if things under files and templates were left alone since they are not actually ansible files.

@EpiqSty
Copy link

EpiqSty commented Apr 23, 2021

It looks like vars_prompt also affected:
with a most basic example: from https://docs.ansible.com/ansible/latest/user_guide/playbooks_prompts.html

---
- hosts: all
  vars_prompt:

    - name: username
      prompt: What is your username?
      private: no

    - name: password
      prompt: What is your password?

  tasks:

    - name: Print a message
      ansible.builtin.debug:
        msg: 'Logging in as {{ username }}'

I'm getting this error:

image

$ apt-cache policy code
code:
  Installed: 1.55.2-1618307277

redhat.vscode-yaml Preview v0.18.0
zbr.vscode-ansible Preview 0.3.2

Please let me know if it's not related and needs a separated issue.

@ssbarnea
Copy link
Member

ssbarnea commented Apr 23, 2021

It looks like vars_prompt also affected:
with a most basic example: from https://docs.ansible.com/ansible/latest/user_guide/playbooks_prompts.html

---
- hosts: all
  vars_prompt:

    - name: username
      prompt: What is your username?
      private: no

    - name: password
      prompt: What is your password?

  tasks:

    - name: Print a message
      ansible.builtin.debug:
        msg: 'Logging in as {{ username }}'

I'm getting this error:

image

$ apt-cache policy code
code:
  Installed: 1.55.2-1618307277

redhat.vscode-yaml Preview v0.18.0
zbr.vscode-ansible Preview 0.3.2

Please let me know if it's not related and needs a separated issue.

The bug is valid and the correct place to raise it is at https://github.com/ansible-community/schemas -- as this is missing from the schema. It should not be hard to add it.

Update: I already made a PR to add it ansible/schemas#32 -- look at it and you will know how to add the next bit we find missing.

@webknjaz webknjaz added the new label Aug 16, 2021
@ssbarnea
Copy link
Member

We are unable to reproduce this with current version of the extension, please upgrade and report if you can see the error.

@ssbarnea ssbarnea removed the new label Oct 29, 2021
ssbarnea added a commit that referenced this issue Mar 15, 2024
While we had eslint configured inside the repository, there was
no CI job running it. This change adds eslint as part
of our existing lint job (pre-commit).

Only two files were automatically reformatted by this change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants