Chapter 4. Manually adding the Ansible language to YAML files


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.

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

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.

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

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",
      }
    }
    Copy to Clipboard Toggle word wrap
Back to top
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2025 Red Hat