Skip to content

Commit fc11f6b

Browse files
committed
fix(schema): Make inventory JSON Schema match actually accepted inventories
1 parent b294d5b commit fc11f6b

File tree

1 file changed

+111
-31
lines changed

1 file changed

+111
-31
lines changed
Lines changed: 111 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,146 @@
11
{
22
"$defs": {
33
"group": {
4+
"additionalProperties": false,
5+
"description": "See https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html#inventory-basics-formats-hosts-and-groups",
46
"properties": {
57
"children": {
8+
"additionalProperties": false,
9+
"description": "See https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html#grouping-groups-parent-child-group-relationships",
10+
"pattern": "^[a-zA-Z_]\\w*$",
611
"patternProperties": {
7-
"[a-zA-Z-_0-9]": {
12+
"^[a-zA-Z_]\\w*$": {
813
"$ref": "#/$defs/group"
914
}
10-
}
15+
},
16+
"title": "Children",
17+
"type": ["object", "string", "null"]
1118
},
1219
"hosts": {
20+
"additionalProperties": false,
21+
"description": "See https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html#inventory-basics-formats-hosts-and-groups",
22+
"examples": [
23+
{
24+
"foo.example.com": null
25+
},
26+
"foo.example.com",
27+
{
28+
"www[01:50].example.com": null
29+
},
30+
{
31+
"www[01:50:2].example.com": null
32+
}
33+
],
34+
"minLength": 1,
1335
"patternProperties": {
14-
"[a-zA-Z.-_0-9]": {
36+
".": {
37+
"additionalProperties": false,
38+
"description": "See https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html#inventory-basics-formats-hosts-and-groups",
39+
"patternProperties": {
40+
"^[a-zA-Z_]\\w*$": {
41+
"title": "Host Variable"
42+
}
43+
},
44+
"title": "Host",
1545
"type": ["object", "null"]
1646
}
1747
},
18-
"type": ["object", "string"]
48+
"title": "Hosts",
49+
"type": ["object", "string", "null"]
1950
},
2051
"vars": {
21-
"type": "object"
52+
"additionalProperties": false,
53+
"description": "See https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html#assigning-a-variable-to-one-machine-host-variables",
54+
"examples": [
55+
{
56+
"ntp_server": "ntp.atlanta.example.com",
57+
"proxy": "proxy.atlanta.example.com"
58+
}
59+
],
60+
"pattern": "^[a-zA-Z_]\\w*$",
61+
"patternProperties": {
62+
"^[a-zA-Z_]\\w*$": {
63+
"title": "Group Variable"
64+
}
65+
},
66+
"title": "Group Variables",
67+
"type": ["object", "string", "null"]
2268
}
2369
},
70+
"title": "Group",
2471
"type": ["object", "null"]
25-
},
26-
"special-group": {
27-
"additionalProperties": false,
28-
"properties": {
29-
"children": {
30-
"type": ["object", "null"]
31-
},
32-
"groups": {
33-
"type": ["object", "null"]
34-
},
35-
"hosts": {
36-
"type": ["object", "null"]
37-
},
38-
"vars": {
39-
"type": ["object", "null"]
40-
}
41-
},
42-
"type": "object"
4372
}
4473
},
4574
"$id": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/inventory.json",
4675
"$schema": "http://json-schema.org/draft-07/schema",
47-
"additionalProperties": true,
76+
"additionalProperties": false,
4877
"description": "See https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html",
4978
"examples": [
50-
"inventory.yaml",
51-
"inventory.yml",
52-
"inventory/*.yml",
53-
"inventory/*.yaml"
79+
{
80+
"dbservers": {
81+
"hosts": {
82+
"one.example.com": null,
83+
"three.example.com": null,
84+
"two.example.com": null
85+
}
86+
},
87+
"ungrouped": {
88+
"hosts": {
89+
"mail.example.com": null
90+
}
91+
},
92+
"webservers": {
93+
"hosts": {
94+
"bar.example.com": null,
95+
"foo.example.com": null
96+
}
97+
}
98+
},
99+
{
100+
"atlanta": {
101+
"hosts": {
102+
"host1": {
103+
"http_port": 80,
104+
"maxRequestsPerChild": 808
105+
},
106+
"host2": {
107+
"http_port": 303,
108+
"maxRequestsPerChild": 909
109+
}
110+
}
111+
}
112+
},
113+
{
114+
"webservers": {
115+
"hosts": {
116+
"www[01:50].example.com": null
117+
}
118+
}
119+
},
120+
{
121+
"webservers": {
122+
"hosts": {
123+
"www[01:50:2].example.com": null
124+
}
125+
}
126+
}
54127
],
55128
"markdownDescription": "All keys at top levels are groups with `all` and `ungrouped` having a special meaning.\n\nSee [How to build your inventory](https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html)",
129+
"patternProperties": {
130+
"^[a-zA-Z_]\\w*$": {
131+
"$ref": "#/$defs/group"
132+
}
133+
},
56134
"properties": {
57135
"all": {
58-
"$ref": "#/$defs/special-group"
136+
"$ref": "#/$defs/group",
137+
"description": "See https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html#default-groups"
59138
},
60139
"ungrouped": {
61-
"$ref": "#/$defs/group"
140+
"$ref": "#/$defs/group",
141+
"description": "See https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html#default-groups"
62142
}
63143
},
64-
"title": "Ansible Inventory Schema",
144+
"title": "Ansible Inventory",
65145
"type": "object"
66146
}

0 commit comments

Comments
 (0)