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

ensure we pre-configure file associations to avoid conflicting with vscode-yaml extension #162

Closed
ssbarnea opened this issue Aug 3, 2021 · 3 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@ssbarnea
Copy link
Member

ssbarnea commented Aug 3, 2021

We need to ensure that vscode-ansible extension can co-exist with vscode-yaml extension and that file using recommended naming and repository layout are automatically detected as ansible while the rest are detected a just yaml.

This can be achieve by using some smart file.associations inside settings.json, like below:

    "files.associations": {
        "**/playbooks/*.yml": "ansible",
        "**/playbooks/*.yaml": "ansible"
    }

I tested and these settings take precedence over the file extension advertised by both extensions, which are quite general.

The tricky part is that extension cannot expose these inside its manifest and the only way to enable them is to modify user settings when it starts first time. Likely we would not want to override user settings with our own patterns, so it needs to a prompt: "Do you want to configure file.associations with ansible file patterns?"

We can extract a relatively complete list of file patterns from https://github.com/ansible-community/ansible-lint/blob/f2fae710c7ccf99e2db2056569d964564403066d/src/ansiblelint/config.py#L14-L58 as the linter already have logic for distinguishing between random yaml files and files owned by ansible.

@ssbarnea ssbarnea added the bug Something isn't working label Aug 3, 2021
@ssbarnea ssbarnea added this to the 1.0.0 milestone Aug 3, 2021
@webknjaz webknjaz added the new label Aug 16, 2021
@cidrblock
Copy link
Contributor

cidrblock commented Aug 16, 2021

add (plugin associations)
site.yml site.yaml main.yml main.yaml tasks/ collections/ansible_collections roles

@ganeshrn ganeshrn removed this from the 1.0.0 milestone Aug 16, 2021
@ganeshrn ganeshrn removed the new label Aug 16, 2021
@ganeshrn ganeshrn added this to the 1.0.0 milestone Aug 16, 2021
@Spacebjorn
Copy link

Spacebjorn commented Aug 30, 2021

I needed all of these settings to get all my files properly associated. I'm sure you're already aware, but maybe it will help somebody else

   "files.associations": {
        "**/playbooks/*.yml": "ansible",
        "**/playbooks/*.yaml": "ansible",
        "**/hostvars/*.yml": "ansible",
        "**/group_vars/*.yml": "ansible",
        "**/tasks/*.yaml": "ansible",
        "**/tasks/*.yml": "ansible",
        "**/defaults/*.yaml": "ansible",
        "**/defaults/*.yml": "ansible",
        "**/vars/*.yaml": "ansible",
        "**/vars/*.yml": "ansible",
        "**/meta/*.yaml": "ansible",
        "**/meta/*.yml": "ansible",
        "**/handlers/*.yaml": "ansible",
        "**/handlers/*.yml": "ansible"
    }

@mconigliaro
Copy link

The solutions above won't work with roles, because playbooks exist at the root level too. That means the only globs that will actually work in all cases are *.yml and *.yaml, which is why I'd argue that the real solution is for Ansible to have its own file extension. I doubt anyone here can do anything about that though.

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

7 participants