Skip to content

Commit

Permalink
Support complex requirements in argument_specs.yml (#3823)
Browse files Browse the repository at this point in the history
  • Loading branch information
tapetersen authored Oct 10, 2023
1 parent 7083eec commit 1e41277
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/ansiblelint/schemas/role-arg-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,70 @@
"default": false,
"type": "boolean"
},
"mutually_exclusive": {
"type": "array",
"items": {
"items": {
"type": "string"
}
}
},
"required_together": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required_one_of": {
"type": "array",
"items": {
"items": {
"type": "string"
}
}
},
"required_if": {
"type": "array",
"items": {
"type": "array",
"prefixItems": [
{
"type": "string"
},
{},
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "boolean"
}
],
"minItems": 3,
"maxItems": 4
}
},
"required_by": {
"type": "object",
"additionalProperties": {
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
},
"type": {
"$ref": "#/$defs/datatype",
"markdownDescription": "See [argument-spec](https://docs.ansible.com/ansible/latest/dev_guide/developing_program_flow_modules.html#argument-spec"
Expand Down
29 changes: 29 additions & 0 deletions test/schemas/test/roles/foo/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,35 @@ argument_specs:
- 3
- 123

complex_required_options:
type: dict
description: Contains sub-options with interacting requirements
options:
foo:
type: str
bar:
type: str
baz:
type: str

mutually_exclusive:
- ["foo", "bar"]

required_together:
- ["bar", "baz"]

required_one_of:
- ["foo", "bar", "baz"]

required_if:
- ["foo", "must_have_bar_and_baz_default", ["bar", "baz"]]
- ["foo", "must_have_bar_and_baz_explicit", ["bar", "baz"], false]
- ["foo", "must_have_one_of_bar_or_baz", ["bar", "baz"], true]

required_by:
foo: "bar"
bar: ["foo", "baz"]

seealso:
- module: community.foo.bar
- module: community.foo.baz
Expand Down

0 comments on commit 1e41277

Please sign in to comment.