Validate data with provided criteria
Version added: 1.0.0
- Validate data with provided criteria based on the validation engine.
Note
- For the type of options data and criteria refer to the individual validate plugin documentation that is represented in the value of engine option.
- For additional plugin configuration options refer to the individual validate plugin documentation that is represented by the value of engine option.
- The plugin configuration option can be either passed as
key=value
pairs within lookup plugin or task or environment variables. - The precedence the validate plugin configurable option is the variable passed within lookup plugin as
key=value
pairs followed by task variables followed by environment variables.
- 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 lookup plugin by passing plugin configuration variable as key/value pairs
ansible.builtin.set_fact:
data_criteria_checks: "{{ lookup('ansible.utils.validate', data, criteria, engine='ansible.utils.jsonschema', draft='draft7') }}"
- name: validate data in json format using jsonschema with lookup plugin by passing plugin configuration variable as task variable
ansible.builtin.set_fact:
data_criteria_checks: "{{ lookup('ansible.utils.validate', data, criteria, engine='ansible.utils.jsonschema', draft='draft7') }}"
vars:
ansible_validate_jsonschema_draft: draft3
Common return values are documented here, the following are the fields unique to this lookup:
Key | Returned | Description |
---|---|---|
_raw
-
|
If data is valid returns empty list.
If data is invalid returns list of errors in data.
|
- Ganesh Nalawade (@ganeshrn)
Hint
Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.