ansible.utils.validate test – Validate data with provided criteria
Note
This test plugin is part of the ansible.utils collection (version 4.1.0).
You might already have this collection installed if you are using the ansible
package.
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install ansible.utils
.
To use it in a playbook, specify: ansible.utils.validate
.
New in ansible.utils 1.0.0
Synopsis
Validate data with provided criteria based on the validation engine.
Keyword parameters
This describes keyword parameters of the test. These are the values key1=value1
, key2=value2
and so on in the following
examples: input is ansible.utils.validate(key1=value1, key2=value2, ...)
and input is not ansible.utils.validate(key1=value1, key2=value2, ...)
Parameter |
Comments |
---|---|
The criteria used for validation of value that represents data options. This option is passed to the test plugin as key, value pair For example For the type of criteria that represents this value refer documentation of individual validate plugins. |
|
A data that will be validated against criteria. This option represents the value that is passed to test plugin as check. For example For the type of data that represents this value refer documentation of individual validate plugins. |
|
The name of the validate plugin to use. This option can be passed in test plugin as a key, value pair For example The value should be in fully qualified collection name format that is <org-name>.<collection-name>.<validate-plugin-name>. Default: |
Notes
Note
For the type of options data and criteria refer the individual validate plugin documentation that is represented in the value of engine option.
For additional plugin configuration options refer 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 test plugin or set as environment variables.The precedence the validate plugin configurable option is the variable passed within test plugin as
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 Value
Key |
Description |
---|---|
If data is valid return If data is invalid return Returned: success |