Set the lanaguge for the VS Code extension

The Ansible VS Code extension works only when the language associated with a file is set to Ansible. The extension provides features that help create Ansible playbooks, such as auto-completion, hover, and diagnostics.

The Ansible VS Code extension automatically associates the Ansible language with some files. The procedures below describe how to set the language for files that are not recognized as Ansible files.

Associate the Ansible language to YAML files

The following procedure describes how to manually assign the Ansible language to a YAML file that is open in VS Code.

About this task

Procedure

  1. Open or create a YAML file in VS Code.
  2. Hover the cursor over the language identified in the status bar at the bottom of the VS Code window to open the Select Language Mode list.
  3. Select Ansible in the list.

    The language shown in the status bar at the bottom of the VS Code window for the file is changed to Ansible.

Add the persistent file association for the Ansible language to settings.json

Instead of manually associating the Ansible language to YAML files, you can add file association for the Ansible language in your settings.json file.

About this task

Procedure

  1. Open the settings.json file:
    1. Click View > Command Palette to open the command palette.
    2. Enter Workspace settings in the search box and select Open Workspace Settings (JSON).
  2. Add the following code to settings.json.
    {
      ...
    
      "files.associations": {
        "*plays.yml": "ansible",
        "*init.yml": "yaml",
      }
    }