17

VSCode: open ansible files with right syntax

 5 years ago
source link: https://www.tuicool.com/articles/hit/RZ3QRnv
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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”.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK