VSCode: open ansible files with right syntax

VSCode extension for Ansible from Microsoft suggestes to open all *.yml files with ansible syntax:

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

This is too wide: you may have YAML files that are not related to ansible.

Also, you need correct syntax highlighting for variables in vars, defaults, group_vars, etc. I recommend Better Jinja extension which supports combined yaml+jinja syntax.

Here is mode precise options to use ansible and yaml+jinja syntax only for right files:

"files.associations": {
    // Ansible
    "**/defaults/**/*.yml": "jinja-yaml",
    "**/group_vars/**/*": "jinja-yaml",
    "**/host_vars/**/*": "jinja-yaml",
    "**/vars/**/*.yml": "jinja-yaml",
    "**/tasks/**/*.yml": "ansible",
    "**/handlers/*.yml": "ansible",
    "**/meta/*.yml": "ansible",
    "**/roles/**/*.yml": "ansible",
    "**/playbooks/**/*.yml": "ansible",
    "**/ansible/**/hosts": "ini",
    "**/ansible/**/inventory": "ini",
    "ansible.cfg": "ini",
},

Open File -> Preferences -> Settings( Ctrl + , ), search for “Files: Associations”, click on “Edit in settings.json”.



License: This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License Share: share on reddit share on hacker news share on facebook share on twitter share on linkedin share on slashdot

No comments

You today

Comments are closed