1---
2title: Ansible
3description: "Configure Ansible language support in Zed, including language servers, formatting, and debugging."
4---
5
6# Ansible
7
8Support for Ansible in Zed is provided via a community-maintained [Ansible extension](https://github.com/kartikvashistha/zed-ansible).
9
10- Tree-sitter: [zed-industries/tree-sitter-yaml](https://github.com/zed-industries/tree-sitter-yaml)
11- Language Server: [ansible/vscode-ansible](https://github.com/ansible/vscode-ansible/tree/main/packages/ansible-language-server)
12
13## Setup
14
15### File detection
16
17To 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 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:
18
19```json [settings]
20"file_types": {
21 "Ansible": [
22 "**.ansible.yml",
23 "**.ansible.yaml",
24 "**/defaults/*.yml",
25 "**/defaults/*.yaml",
26 "**/meta/*.yml",
27 "**/meta/*.yaml",
28 "**/tasks/*.yml",
29 "**/tasks/*.yaml",
30 "**/handlers/*.yml",
31 "**/handlers/*.yaml",
32 "**/group_vars/*.yml",
33 "**/group_vars/*.yaml",
34 "**/host_vars/*.yml",
35 "**/host_vars/*.yaml",
36 "**/playbooks/*.yml",
37 "**/playbooks/*.yaml",
38 "**playbook*.yml",
39 "**playbook*.yaml"
40 ]
41 }
42```
43
44Feel free to modify this list as per your needs.
45
46#### Inventory
47
48If your inventory file is in the YAML format, you can either:
49
50- Append the `ansible-lint` inventory json schema to it via the following comment at the top of your inventory file:
51
52```yml
53# yaml-language-server: $schema=https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/inventory.json
54```
55
56- Or configure the yaml language server settings to set this schema for all your inventory files, that match your inventory pattern, under your Zed settings ([ref](https://zed.dev/docs/languages/yaml)):
57
58```json [settings]
59"lsp": {
60 "yaml-language-server": {
61 "settings": {
62 "yaml": {
63 "schemas": {
64 "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/inventory.json": [
65 "./inventory/*.yaml",
66 "hosts.yml",
67 ]
68 }
69 }
70 }
71 }
72},
73```
74
75### LSP Configuration
76
77By default, the following default config is passed to the Ansible language server. It conveniently mirrors the defaults set by [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig/blob/03bc581e05e81d33808b42b2d7e76d70adb3b595/lua/lspconfig/configs/ansiblels.lua) for the Ansible language server:
78
79```json [settings]
80{
81 "ansible": {
82 "ansible": {
83 "path": "ansible"
84 },
85 "executionEnvironment": {
86 "enabled": false
87 },
88 "python": {
89 "interpreterPath": "python3"
90 },
91 "validation": {
92 "enabled": true,
93 "lint": {
94 "enabled": true,
95 "path": "ansible-lint"
96 }
97 }
98 }
99}
100```
101
102> [!NOTE]
103> In order for linting to work, ensure that `ansible-lint` is installed and discoverable on your PATH
104
105When desired, any of the above default settings can be overridden under the `"lsp"` section of your Zed settings file. For example:
106
107```json [settings]
108"lsp": {
109 // Note, the Zed Ansible extension prefixes all settings with `ansible`
110 // so instead of using `ansible.ansible.path` use `ansible.path`.
111 "ansible-language-server": {
112 "settings": {
113 "ansible": {
114 "path": "ansible"
115 },
116 "executionEnvironment": {
117 "enabled": false
118 },
119 "python": {
120 "interpreterPath": "python3"
121 },
122 "validation": {
123 "enabled": false, // disable validation
124 "lint": {
125 "enabled": false, // disable ansible-lint
126 "path": "ansible-lint"
127 }
128 }
129 }
130 }
131}
132```
133
134A full list of options/settings, that can be passed to the server, can be found at the project's page [here](https://github.com/ansible/vscode-ansible/blob/5a89836d66d470fb9d20e7ea8aa2af96f12f61fb/docs/als/settings.md).
135Feel free to modify option values as needed.