Ansible - Zed

# Ansible

Support for Ansible in Zed is provided via a community-maintained Ansible extension.

- Tree-sitter: zed-industries/tree-sitter-yaml
- Language Server: ansible/vscode-ansible

## Setup

### File detection

By default, to avoid mishandling non-Ansible YAML files, the Ansible Language is not associated with any file extensions by default. To change this behavior you can add a `"file_types"` section to the Zed settings inside your project (`.zed/settings.json`) or your Zed user settings (`~/.config/zed/settings.json`) to match your folder/naming conventions. For example:

    "file_types": {
        "Ansible": [
          "**.ansible.yml",
          "**.ansible.yaml",
          "**/defaults/*.yml",
          "**/defaults/*.yaml",
          "**/meta/*.yml",
          "**/meta/*.yaml",
          "**/tasks/*.yml",
          "**/tasks/*.yaml",
          "**/handlers/*.yml",
          "**/handlers/*.yaml",
          "**/group_vars/*.yml",
          "**/group_vars/*.yaml",
          "**/playbooks/*.yml",
          "**/playbooks/*.yaml",
          "**playbook*.yml",
          "**playbook*.yaml"
        ]
      }

Feel free to modify this list as per your needs.

### LSP Configuration

LSP options for this extension can be configured under Zed's settings file. To get the best experience, add the following configuration under the `"lsp"` section in your `~/.zed/settings.json`:

    "lsp": {
      // Note, the Zed Ansible extension prefixes all settings with `ansible`
      // so instead of using `ansible.ansible.path` use `ansible.path`.
      "ansible-language-server": {
        "settings": {
          "ansible": {
            "path": "ansible"
          },
          "executionEnvironment": {
            "enabled": false
          },
          "python": {
            "interpreterPath": "python3"
          },
          "validation": {
            "enabled": true,
            // To enable linting, manually install ansible-lint and make sure it is your PATH
            "lint": {
              "enabled": true,
              "path": "ansible-lint"
            }
          }
        }
      }
    }

This config was conveniently adopted from nvim-lspconfig.

A full list of options/settings, that can be passed to the server, can be found at the project's page here. Feel free to modify option values as needed.