validate¶
Collection Note
This module is part of the ansible.utils collection. To install the collection, use:
Added in version1.0.0.
Synopsis¶
- Validate I(data) with provided I(criteria) based on the validation I(engine).
Parameters¶
| Parameter | Defaults / Choices | Comments |
|---|---|---|
| criteria raw required |
The criteria used for validation of value that represents I(data) options. This option is passed to the test plugin as key, value pair For example C(config_data is ansible.utils.validate(criteria=criteria)), in this case the value of I(criteria) key represents this criteria for data validation. For the type of I(criteria) that represents this value refer documentation of individual validate plugins. |
|
| data raw required |
A data that will be validated against I(criteria). This option represents the value that is passed to test plugin as check. For example C(config_data is ansible.utils.validate(criteria=criteria), in this case B(config_data) represents this option. For the type of I(data) that represents this value refer documentation of individual validate plugins. |
|
| engine str |
Default: ansible.utils.jsonschema |
The name of the validate plugin to use. This option can be passed in test plugin as a key, value pair For example C(config_data is ansible.utils.validate(engine='ansible.utils.jsonschema', criteria=criteria)), in this case the value of I(engine) key represents the engine to be use for data validation. If the value is not provided the default value that is C(ansible.utils.jsonschema) will be used. The value should be in fully qualified collection name format that is B( |
Notes¶
Note
- For the type of options I(data) and I(criteria) refer the individual validate plugin documentation that is represented in the value of I(engine) option.
- For additional plugin configuration options refer the individual validate plugin documentation that is represented by the value of I(engine) option.
- The plugin configuration option can be either passed as C(key=value) pairs within test plugin or set as environment variables.
- The precedence the validate plugin configurable option is the variable passed within test plugin as C(key=value) pairs followed by task variables followed by environment variables.
Examples¶
- name: set facts for data and criteria
ansible.builtin.set_fact:
data: "{{ lookup('ansible.builtin.file', './validate/data/show_interfaces_iosxr.json')}}"
criteria: "{{ lookup('ansible.builtin.file', './validate/criteria/jsonschema/show_interfaces_iosxr.json')}}"
- name: validate data in json format using jsonschema with test plugin
ansible.builtin.set_fact:
is_data_valid: "{{ data is ansible.utils.validate(engine='ansible.utils.jsonschema', criteria=criteria, draft='draft7') }}"
Return Values¶
| Key | Data Type | Description | Returned |
|---|---|---|---|
| _raw | If data is valid return C(true) If data is invalid return C(false) |
Authors¶
- Ganesh Nalawade (@ganeshrn)