ansible.utils.validate – Validate data with provided criteria

Note

This plugin is part of the ansible.utils collection (version 2.4.2).

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 version 1.0.0: of ansible.utils

Synopsis

  • Validate data with provided criteria based on the validation engine.

Parameters

Parameter Choices/Defaults Configuration Comments
criteria
raw / required
The criteria used for validation of value that represents data options.
This option represents the second argument passed in the lookup plugin For example lookup(config_data, config_criteria, engine='ansible.utils.jsonschema'), in this case the value of config_criteria represents this option.
For the type of criteria that represents this value refer to the documentation of individual validate plugins.
data
raw / required
Data that will be validated against criteria.
This option represents the value that is passed to the lookup plugin as the first argument. For example lookup(config_data, config_criteria, engine='ansible.utils.jsonschema'), in this case config_data represents this option.
For the type of data that represents this value refer to the documentation of individual validate plugins.
engine
string
Default:
"ansible.utils.jsonschema"
The name of the validate plugin to use.
This option can be passed in lookup plugin as a key, value pair. For example lookup(config_data, config_criteria, engine='ansible.utils.jsonschema'), in this case the value ansible.utils.jsonschema represents the engine to be use for data validation. If the value is not provided the default value that is ansible.uitls.jsonschema will be used.
The value should be in fully qualified collection name format that is <org-name>.<collection-name>.<validate-plugin-name>.

Notes

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.

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 lookup plugin by passing plugin configuration variable as key/value pairs
  ansible.builtin.set_fact:
    data_criteria_checks: "{{ lookup(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

Return Values

Common return values are documented here, the following are the fields unique to this lookup:

Key Returned Description
_raw
string
success
If data is valid returns empty list.
If data is invalid returns list of errors in data.



Authors

  • Ganesh Nalawade (@ganeshrn)

© 2012–2018 Michael DeHaan
© 2018–2021 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/ansible/utils/validate_lookup.html