Skip to content

Commit 3942375

Browse files
Add schema check for validating pattern specification file (#4653)
Co-authored-by: Sorin Sbarnea <[email protected]>
1 parent 155b48c commit 3942375

File tree

10 files changed

+466
-3
lines changed

10 files changed

+466
-3
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"schema_version": "1.0",
3+
"name": "weather_forecasting",
4+
"title": "Weather Forecasting",
5+
"description": "This pattern is designed to help get the weather forecast for a given airport code. It creates a project, EE, and job templates in automation controller to get the weather forecast.",
6+
"short_description": "This pattern is designed to help get the weather forecast for a given airport code.",
7+
"tags": ["weather", "forecasting"],
8+
"aap_resources": {
9+
"controller_project": {
10+
"name": "Weather Forecasting",
11+
"description": "Project for the Weather Forecasting pattern"
12+
},
13+
"controller_execution_environment": {
14+
"name": "Weather Forecasting",
15+
"description": "EE for the Weather Forecasting pattern",
16+
"image_name": "weather-demo-ee",
17+
"pull": "missing"
18+
},
19+
"controller_labels": ["weather", "forecasting"],
20+
"controller_job_templates": [
21+
{
22+
"name": "Get Weather Forecast",
23+
"description": "This job template gets the weather at the location of a provided airport code.",
24+
"execution_environment": "Weather Forecasting",
25+
"playbook": "site.yml",
26+
"primary": true,
27+
"labels": ["weather", "forecasting"],
28+
"survey": {
29+
"name": "Weather Forecasting",
30+
"description": "Survey to configure the weather forecasting pattern",
31+
"spec": [
32+
{
33+
"type": "text",
34+
"question_name": "Location",
35+
"question_description": "Enter the airport code for which you want to get the weather forecast",
36+
"variable": "location",
37+
"required": true
38+
}
39+
]
40+
}
41+
}
42+
]
43+
}
44+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"schema_version": "1.0",
3+
"title": "Weather Forecasting",
4+
"description": "This pattern is designed to help get the weather forecast for a given airport code. It creates a project, EE, and job templates in automation controller to get the weather forecast.",
5+
"short_description": "This pattern is designed to help get the weather forecast for a given airport code.",
6+
"tags": ["weather", "forecasting"],
7+
"aap_resources": {
8+
"controller_project": {
9+
"name": "Weather Forecasting",
10+
"description": "Project for the Weather Forecasting pattern"
11+
},
12+
"controller_execution_environment": {
13+
"name": "Weather Forecasting",
14+
"description": "EE for the Weather Forecasting pattern",
15+
"image_name": "weather-demo-ee",
16+
"pull": "missing"
17+
},
18+
"controller_labels": ["weather", "forecasting"],
19+
"controller_job_templates": [
20+
{
21+
"name": "Get Weather Forecast",
22+
"description": "This job template gets the weather at the location of a provided airport code.",
23+
"execution_environment": "Weather Forecasting",
24+
"playbook": "site.yml",
25+
"primary": true,
26+
"labels": ["weather", "forecasting"],
27+
"survey": {
28+
"name": "Weather Forecasting",
29+
"description": "Survey to configure the weather forecasting pattern",
30+
"spec": [
31+
{
32+
"type": "text",
33+
"question_name": "Location",
34+
"question_description": "Enter the airport code for which you want to get the weather forecast",
35+
"variable": "location",
36+
"required": true
37+
}
38+
]
39+
}
40+
}
41+
]
42+
}
43+
}

src/ansiblelint/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
{"vars": "**/{host_vars,group_vars,vars,defaults}/**/*.{yaml,yml}"},
5454
{"tasks": "**/tasks/**/*.{yaml,yml}"},
5555
{"rulebook": "**/rulebooks/*.{yml,yaml"},
56+
{"pattern": "**/patterns/*/meta/pattern.json"},
5657
{"playbook": "**/playbooks/*.{yml,yaml}"},
5758
{"playbook": "**/*playbook*.{yml,yaml}"},
5859
{"role": "**/roles/*/"},

src/ansiblelint/rules/schema.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ project:
4040
or
4141
[role/metadata.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/playbook/role/metadata.py#L79))
4242
for details.
43+
- `schema[pattern]` validates Ansible patterns.
4344
- `schema[playbook]` validates Ansible playbooks.
4445
- `schema[requirements]` validates Ansible
4546
[requirements](https://docs.ansible.com/ansible/latest/galaxy/user_guide.html#install-multiple-collections-with-a-requirements-file)

src/ansiblelint/rules/schema.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class ValidateSchemaRule(AnsibleLintRule):
6262
id = "schema"
6363
severity = "VERY_HIGH"
6464
tags = ["core"]
65-
version_changed = "6.1.0"
65+
version_changed = "25.7.0"
6666
_ids = {
6767
"schema[ansible-lint-config]": "",
6868
"schema[ansible-navigator-config]": "",
@@ -73,6 +73,7 @@ class ValidateSchemaRule(AnsibleLintRule):
7373
"schema[meta]": "",
7474
"schema[meta-runtime]": "",
7575
"schema[molecule]": "",
76+
"schema[pattern]": "",
7677
"schema[playbook]": "",
7778
"schema[requirements]": "",
7879
"schema[role-arg-spec]": "",
@@ -367,6 +368,20 @@ def matchyaml(self, file: Lintable) -> list[MatchError]:
367368
],
368369
id="playbook2",
369370
),
371+
pytest.param(
372+
"examples/patterns/correct_pattern/meta/pattern.json",
373+
"pattern",
374+
[],
375+
id="pattern_positive",
376+
),
377+
pytest.param(
378+
"examples/patterns/incorrect_pattern/meta/pattern.json",
379+
"pattern",
380+
[
381+
r"\$ 'name' is a required property",
382+
],
383+
id="pattern_negative",
384+
),
370385
),
371386
)
372387
def test_schema(

src/ansiblelint/schemas/__store__.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
"etag": "3b625438c28e884ac42a14c09ca542fc3e1b4466abaf47d0c28646e0857d3fb5",
3636
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/molecule.json"
3737
},
38+
"pattern": {
39+
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/pattern.json"
40+
},
3841
"playbook": {
3942
"etag": "4f8cbba62fcf8a1fa6e8ef5e42696aec5b0876487478df83a7ffdf8bdbb4abcf",
4043
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/playbook.json"

0 commit comments

Comments
 (0)