ansible.utils.validate (4.0.0) — filter

Validate data with provided criteria

| "added in version" 1.0.0 of ansible.utils"

Authors: Ganesh Nalawade (@ganeshrn)

Install collection

Install with ansible-galaxy collection install ansible.utils:==4.0.0


Add to requirements.yml

  collections:
    - name: ansible.utils
      version: 4.0.0

Description

Validate I(data) with provided I(criteria) based on the validation I(engine).

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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')}}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: validate data in json format using jsonschema by passing plugin configuration variable as key/value pairs
  ansible.builtin.set_fact:
    data_validity: "{{ data|ansible.utils.validate(criteria, engine='ansible.utils.jsonschema', draft='draft7') }}"

Inputs

    
data:
    description:
    - Data that will be validated against I(criteria).
    - This option represents the value that is passed to the filter plugin in pipe format.
      For example C(config_data|ansible.utils.validate()), in this case C(config_data)
      represents this option.
    - For the type of I(data) that represents this value refer to the documentation of
      individual validator plugins.
    required: true
    type: raw

engine:
    default: ansible.utils.jsonschema
    description:
    - The name of the validator plugin to use.
    - This option can be passed in lookup plugin as a key, value pair. For example C(config_data|ansible.utils.validate(config_criteria,
      engine='ansible.utils.jsonschema')), in this case the value C(ansible.utils.jsonschema)
      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 C(<org-name>.<collection-name>.<validator-plugin-name>).
    type: str

criteria:
    description:
    - The criteria used for validation of value that represents I(data) options.
    - This option represents the first argument passed in the filter plugin. For example
      C(config_data|ansible.utils.validate(config_criteria)), in this case the value of
      C(config_criteria) represents this option.
    - For the type of I(criteria) that represents this value refer to the  documentation
      of individual validator plugins.
    required: true
    type: raw

Outputs

_raw:
  description:
  - If data is valid returns empty list
  - If data is invalid returns list of errors in data