vscode-ansible icon indicating copy to clipboard operation
vscode-ansible copied to clipboard

Add support for generic playbook directory structure

Open nshores opened this issue 3 years ago • 3 comments

Currently this plugin expects you to have ansible yml files in the following directory structure:


      {
        "fileMatch": "requirements.yml",
        "url": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-requirements.json"
      },
      {
        "fileMatch": "meta/main.yml",
        "url": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-meta.json"
      },
      {
        "fileMatch": ["vars/*.yml", "defaults/*.yml", "host_vars/*.yml", "group_vars/*.yml"],
        "url": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-vars.json"
      },
      {
        "fileMatch": ["tasks/*.yml", "handlers/*.yml"],
        "url": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-tasks.json"
      },
      {
        "fileMatch": ["playbooks/*.yml", "playbooks/*.yaml"],
        "url": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-playbook.json"
      }

If you have your playbook in another folder, say ansible/main.yml it will not match. This should be worked around to implement a broader match for valid ansible yml files.

nshores avatar Feb 26 '21 17:02 nshores

I was sure this request will come at some point but I was expecting to see it first with the linter, which has the same issue.

I am mot sure if is possible to dynamically tell yaml extension to add extra patterns. Even if sorted you will also have to add the same custom directory to the linter config too.

I am afraid there is no end to the amount of troubles you will endup by not following the current guidelines (folder named playbooks). We can blame Ansible team for not documenting that for a long time. On the other hand, I seen the same folder name “ansible” mentioned at least once in the linter this month too, so it may prove to be a popular choice. Is that is true and we do not spot conflicts, we could try to add it as to the defaults. Still for any defaults we need to gather data to avoid to avoid solving a problem for X users at the cost of breaking it for other Y of them. I am yet sure how we could survey that well.

ssbarnea avatar Feb 27 '21 07:02 ssbarnea

I use files layout like /etc/ansible.projects:

roles/
playbook.yml

where my own roles inside roles/ folder above, and galaxy roles inside /etc/ansible/roles and I get a bunch of lint errors on galaxy roles. but it points to random strings in my playbook.yml

MVKozlov avatar Mar 16 '21 12:03 MVKozlov

I am still trying to address this but it involves changes in two other extensions, fixing it inside vscode-ansible is not possible until https://github.com/microsoft/vscode-json-languageservice/issues/80 and https://github.com/redhat-developer/yaml-language-server/issues/422 are addressed (likely first one will fix the second).

ssbarnea avatar Mar 16 '21 14:03 ssbarnea