ansible.utils.validate (4.0.0) — module

Validate data with provided criteria

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

Authors: Bradley Thornton (@cidrblock), Ganesh Nalawade (@ganeshrn)

This plugin has a corresponding action plugin.

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 data with provided criteria based on the validation 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 with jsonschema engine (by passing task vars as configurable plugin options)
  ansible.utils.validate:
    data: "{{ data }}"
    criteria: "{{ criteria }}"
    engine: ansible.utils.jsonschema
  vars:
    ansible_jsonschema_draft: draft7
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: validate configuration with config plugin (see config plugin for criteria examples)
  ansible.utils.validate:
    data: "{{ lookup('ansible.builtin.file', './backup/eos.config') }}"
    criteria: "{{ lookup('ansible.builtin.file', './validate/criteria/config/eos_config_rules.yaml') }}"
    engine: ansible.utils.config

Inputs

    
data:
    description:
    - Data that will be validated against I(criteria). For the type of data refer to the
      documentation of individual validate plugins.
    required: true
    type: raw

engine:
    default: ansible.utils.jsonschema
    description:
    - The name of the validate plugin to use. The engine value should follow the fully
      qualified collection name format, that is <org-name>.<collection-name>.<validate-plugin-name>.
    type: str

criteria:
    description:
    - The criteria used for validation of I(data). For the type of criteria refer to the
      documentation of individual validate plugins.
    required: true
    type: raw

Outputs

errors:
  description: The list of errors in I(data) based on the I(criteria).
  elements: str
  returned: when I(data) value is invalid
  type: list
msg:
  description:
  - The msg indicates if the I(data) is valid as per the I(criteria).
  - In case data is valid return success message B(all checks passed).
  - In case data is invalid return error message B(Validation errors were found) along
    with more information on error is available.
  returned: always
  type: str