mirror of https://github.com/ansible/ansible.git
Fix validate_argument_spec so the argument spec is validated before
passing it to the ArgumentSpecValidator to prevent unhandled errors during variable validation. Make role argument spec errors non-fatal at runtime. Display a warning and include details with -vvv. Pass ArgumentSpecValidator a pruned argument spec containing the valid portion. Give an error and return argument_spec_errors in the task result for non-implicit validate_argument_spec tasks. Add tests for role argument spec errors and validate_argument_spec argument_spec errors.pull/79657/head
parent
48be6f8b6f
commit
4ba445b748
@ -0,0 +1,6 @@
|
||||
bugfixes:
|
||||
- >
|
||||
roles - give a warning for unsupported fields in the role argument spec during implicit ``validate_argument_spec`` tasks.
|
||||
The valid portion of the argument spec is used to validate variables to prevent unhandled errors during validation.
|
||||
(https://github.com/ansible/ansible/issues/79624, https://github.com/ansible/ansible/issues/84103)
|
||||
- validate_argument_spec - give an error for unsupported fields in the argument spec to prevent unhandled errors during validation.
|
@ -0,0 +1,67 @@
|
||||
---
|
||||
argument_specs:
|
||||
no_log:
|
||||
short_description: "Validate no_log in a role argument spec causes a warning."
|
||||
description:
|
||||
- "The validation for role argument specs is read-only and does not provide a way to mark a variable as no_log."
|
||||
options:
|
||||
password:
|
||||
description: "Things not to do."
|
||||
no_log: true
|
||||
|
||||
no_log_suboption:
|
||||
short_description: "Validate no_log in a role argument spec causes a warning."
|
||||
description:
|
||||
- "The validation for role argument specs is read-only and does not provide a way to mark a subset of a variable as no_log."
|
||||
options:
|
||||
auth:
|
||||
description: "A dictionary containing a no_log suboption."
|
||||
type: dict
|
||||
options:
|
||||
password:
|
||||
description: "Things not to do."
|
||||
no_log: true
|
||||
|
||||
apply_defaults:
|
||||
short_description: "Validate apply_defaults in a role argument spec causes a warning."
|
||||
description:
|
||||
- "The validation for role argument specs is read-only and does not provide a way to set a variable."
|
||||
options:
|
||||
option_with_suboptions:
|
||||
description: "Things not to do."
|
||||
type: dict
|
||||
apply_defaults: true
|
||||
options:
|
||||
sub_option:
|
||||
description: "A suboption of an option with apply_defaults."
|
||||
default: "magic"
|
||||
|
||||
aliases:
|
||||
short_description: "Validate aliases in a role argument spec causes a warning."
|
||||
description:
|
||||
- "The validation for role argument specs is read-only and does not provide a way to set a variable to an alias."
|
||||
options:
|
||||
option_name:
|
||||
description: "Things not to do."
|
||||
aliases:
|
||||
- option_alias
|
||||
|
||||
fallback:
|
||||
short_description: "Validate fallback in a role argument spec causes a warning."
|
||||
description:
|
||||
- "The validation for role argument specs is read-only and does not provide a way to set a variable to an environment variable."
|
||||
options:
|
||||
option_with_env_fallback:
|
||||
description: "Things not to do."
|
||||
fallback:
|
||||
- ENV_VAR
|
||||
|
||||
unknown_field:
|
||||
short_description: "Validate an unknown field in a role argument spec causes a warning."
|
||||
description:
|
||||
- "Help detect typos."
|
||||
options:
|
||||
option_name:
|
||||
description: "Things not to do."
|
||||
unknown: "yes"
|
||||
choice: ["typo"]
|
@ -0,0 +1 @@
|
||||
shippable/posix/group2
|
@ -0,0 +1,59 @@
|
||||
- name: Validate task vars with an argument spec
|
||||
validate_argument_spec:
|
||||
argument_spec:
|
||||
option_with_suboptions:
|
||||
type: dict
|
||||
options:
|
||||
required_suboption:
|
||||
type: str
|
||||
required: true
|
||||
vars:
|
||||
option_with_suboptions:
|
||||
required_suboption: specified
|
||||
|
||||
- name: Validate an argument spec containing invalid suboptions
|
||||
validate_argument_spec:
|
||||
argument_spec:
|
||||
invalid_suboptions:
|
||||
description: Valid top level option containing non-string options.
|
||||
type: dict
|
||||
options:
|
||||
true:
|
||||
description: Invalid suboption name.
|
||||
invalid_option:
|
||||
description: Not a dictionary or list.
|
||||
type: str
|
||||
options:
|
||||
suboption:
|
||||
type: str
|
||||
ignore_errors: true
|
||||
register: validation_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- validation_result is failed
|
||||
- validation_result.msg == "Invalid argument_spec cannot be used to validate variables."
|
||||
- validation_result.argument_spec_errors|length == 2
|
||||
- validation_result.argument_spec_errors == [error1, error2]
|
||||
vars:
|
||||
error1: "invalid_suboptions.True: type <class 'bool'>. Option names must be strings."
|
||||
error2: "invalid_option: options. Suboptions are supported for types dict and list."
|
||||
|
||||
- name: Validate an argument spec containing an unsupported field for an option
|
||||
validate_argument_spec:
|
||||
argument_spec:
|
||||
option1:
|
||||
fallback:
|
||||
- env_fallback # ArgumentSpecValidator expects a callable, so fallback is unsupported for validate_argument_spec
|
||||
- [ENV_VAR]
|
||||
ignore_errors: true
|
||||
register: validation_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- validation_result is failed
|
||||
- validation_result.msg == "Invalid argument_spec cannot be used to validate variables."
|
||||
- validation_result.argument_spec_errors|length == 1
|
||||
- validation_result.argument_spec_errors == ["option1: fallback. " ~ valid_params]
|
||||
vars:
|
||||
valid_params: "Supported parameters include: aliases, apply_defaults, choices, default, description, elements, no_log, options, required, type, version_added."
|
Loading…
Reference in New Issue