parent
1807ee7c7b
commit
884105f112
|
@ -24,6 +24,7 @@ Name | Description
|
|||
[ansible.utils.get_path](https://github.com/ansible-collections/ansible.utils/blob/main/docs/ansible.utils.get_path_filter.rst)|Retrieve the value in a variable using a path
|
||||
[ansible.utils.index_of](https://github.com/ansible-collections/ansible.utils/blob/main/docs/ansible.utils.index_of_filter.rst)|Find the indicies of items in a list matching some criteria
|
||||
[ansible.utils.to_paths](https://github.com/ansible-collections/ansible.utils/blob/main/docs/ansible.utils.to_paths_filter.rst)|Flatten a complex object into a dictionary of paths and values
|
||||
[ansible.utils.validate](https://github.com/ansible-collections/ansible.utils/blob/main/docs/ansible.utils.validate_filter.rst)|Validate data with provided criteria
|
||||
|
||||
### Lookup plugins
|
||||
Name | Description
|
||||
|
@ -31,12 +32,19 @@ Name | Description
|
|||
[ansible.utils.get_path](https://github.com/ansible-collections/ansible.utils/blob/main/docs/ansible.utils.get_path_lookup.rst)|Retrieve the value in a variable using a path
|
||||
[ansible.utils.index_of](https://github.com/ansible-collections/ansible.utils/blob/main/docs/ansible.utils.index_of_lookup.rst)|Find the indicies of items in a list matching some criteria
|
||||
[ansible.utils.to_paths](https://github.com/ansible-collections/ansible.utils/blob/main/docs/ansible.utils.to_paths_lookup.rst)|Flatten a complex object into a dictionary of paths and values
|
||||
[ansible.utils.validate](https://github.com/ansible-collections/ansible.utils/blob/main/docs/ansible.utils.validate_lookup.rst)|Validate data with provided criteria
|
||||
|
||||
### Modules
|
||||
Name | Description
|
||||
--- | ---
|
||||
[ansible.utils.fact_diff](https://github.com/ansible-collections/ansible.utils/blob/main/docs/ansible.utils.fact_diff_module.rst)|Find the difference between currently set facts
|
||||
[ansible.utils.update_fact](https://github.com/ansible-collections/ansible.utils/blob/main/docs/ansible.utils.update_fact_module.rst)|Update currently set facts
|
||||
[ansible.utils.validate](https://github.com/ansible-collections/ansible.utils/blob/main/docs/ansible.utils.validate_module.rst)|Validate data with provided criteria
|
||||
|
||||
### Test plugins
|
||||
Name | Description
|
||||
--- | ---
|
||||
[ansible.utils.validate](https://github.com/ansible-collections/ansible.utils/blob/main/docs/ansible.utils.validate_test.rst)|Validate data with provided criteria
|
||||
|
||||
<!--end collection content-->
|
||||
|
||||
|
|
|
@ -223,11 +223,6 @@ Examples
|
|||
|
||||
# changed: [localhost]
|
||||
|
||||
- name: Show the difference in yaml format
|
||||
ansible.utils.fact_diff:
|
||||
before: "{{ before }}"
|
||||
after: "{{ before }}"
|
||||
|
||||
|
||||
#### Show the difference between complex object using restconf
|
||||
# ansible_connection: ansible.netcommon.httpapi
|
||||
|
@ -235,7 +230,7 @@ Examples
|
|||
# ansible_httpapi_validate_certs: False
|
||||
# ansible_network_os: ansible.netcommon.restconf
|
||||
|
||||
- name: Get the current interface config prior ro changes
|
||||
- name: Get the current interface config prior to changes
|
||||
ansible.netcommon.restconf_get:
|
||||
content: config
|
||||
path: /data/Cisco-NX-OS-device:System/intf-items/phys-items
|
||||
|
|
|
@ -0,0 +1,171 @@
|
|||
.. _ansible.utils.validate_filter:
|
||||
|
||||
|
||||
**********************
|
||||
ansible.utils.validate
|
||||
**********************
|
||||
|
||||
**Validate data with provided criteria**
|
||||
|
||||
|
||||
Version added: 1.0.0
|
||||
|
||||
.. contents::
|
||||
:local:
|
||||
:depth: 1
|
||||
|
||||
|
||||
Synopsis
|
||||
--------
|
||||
- Validate ``data`` with provided ``criteria`` based on the validation ``engine``.
|
||||
|
||||
|
||||
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<table border=0 cellpadding=0 class="documentation-table">
|
||||
<tr>
|
||||
<th colspan="1">Parameter</th>
|
||||
<th>Choices/<font color="blue">Defaults</font></th>
|
||||
<th>Configuration</th>
|
||||
<th width="100%">Comments</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="1">
|
||||
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||
<b>criteria</b>
|
||||
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||
<div style="font-size: small">
|
||||
<span style="color: purple">raw</span>
|
||||
/ <span style="color: red">required</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
<div>The criteria used for validation of value that represents <code>data</code> options.</div>
|
||||
<div>This option represents the first argument passed in the filter plugin For example <em>config_data|ansible.utils.validate(config_criteria</em>), in this case the value of <em>config_criteria</em> represents this option.</div>
|
||||
<div>For the type of <code>criteria</code> that represents this value refer documentation of individual validator plugins.</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="1">
|
||||
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||
<b>data</b>
|
||||
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||
<div style="font-size: small">
|
||||
<span style="color: purple">raw</span>
|
||||
/ <span style="color: red">required</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
<div>A data that will be validated against <code>criteria</code>.</div>
|
||||
<div>This option represents the value that is passed to filter plugin in pipe format. For example <em>config_data|ansible.utils.validate(</em>), in this case <em>config_data</em> represents this option.</div>
|
||||
<div>For the type of <code>data</code> that represents this value refer documentation of individual validator plugins.</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="1">
|
||||
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||
<b>engine</b>
|
||||
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||
<div style="font-size: small">
|
||||
<span style="color: purple">string</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<b>Default:</b><br/><div style="color: blue">"ansible.utils.jsonschema"</div>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
<div>The name of the validator plugin to use.</div>
|
||||
<div>This option can be passed in lookup plugin as a key, value pair For example <em>config_data|ansible.utils.validate(config_criteria, engine='ansible.utils.jsonschema'</em>), in this case the value <em>ansible.utils.jsonschema</em> represents the engine to be use for data valdiation. If the value is not provided the default value that is <em>ansible.uitls.jsonschema</em> will be used.</div>
|
||||
<div>The value should be in fully qualified collection name format that is <em><org-name>.<collection-name>.<validator-plugin-name></em>.</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br/>
|
||||
|
||||
|
||||
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 filter plugin or environment variables.
|
||||
- The precedence of the ``validate`` plugin configurable option is the variable passed within filter plugin as *key=value* pairs followed by the environment variables.
|
||||
|
||||
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
- name: set facts for data and criteria
|
||||
set_fact:
|
||||
data: "{{ lookup('file', './validate/data/show_interfaces_iosxr.json')}}"
|
||||
criteria: "{{ lookup('file', './validate/criteria/jsonschema/show_interfaces_iosxr.json')}}"
|
||||
|
||||
- name: validate data in json format using jsonschema with by passing plugin configuration variable as key/value pairs
|
||||
ansible.builtin.set_fact:
|
||||
data_validilty: "{{ data|ansible.utils.validate(criteria, engine='ansible.utils.jsonschema', draft='draft7') }}"
|
||||
|
||||
|
||||
|
||||
Return Values
|
||||
-------------
|
||||
Common return values are documented `here <https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#common-return-values>`_, the following are the fields unique to this filter:
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<table border=0 cellpadding=0 class="documentation-table">
|
||||
<tr>
|
||||
<th colspan="1">Key</th>
|
||||
<th>Returned</th>
|
||||
<th width="100%">Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="1">
|
||||
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||
<b>_raw</b>
|
||||
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||
<div style="font-size: small">
|
||||
<span style="color: purple">-</span>
|
||||
</div>
|
||||
</td>
|
||||
<td></td>
|
||||
<td>
|
||||
<div>If data is valid returns empty list</div>
|
||||
<div>If data is invalid returns list of errors in data</div>
|
||||
<br/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br/><br/>
|
||||
|
||||
|
||||
Status
|
||||
------
|
||||
|
||||
|
||||
Authors
|
||||
~~~~~~~
|
||||
|
||||
- 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.
|
|
@ -0,0 +1,177 @@
|
|||
.. _ansible.utils.validate_lookup:
|
||||
|
||||
|
||||
**********************
|
||||
ansible.utils.validate
|
||||
**********************
|
||||
|
||||
**Validate data with provided criteria**
|
||||
|
||||
|
||||
Version added: 1.0.0
|
||||
|
||||
.. contents::
|
||||
:local:
|
||||
:depth: 1
|
||||
|
||||
|
||||
Synopsis
|
||||
--------
|
||||
- Validate ``data`` with provided ``criteria`` based on the validation ``engine``.
|
||||
|
||||
|
||||
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<table border=0 cellpadding=0 class="documentation-table">
|
||||
<tr>
|
||||
<th colspan="1">Parameter</th>
|
||||
<th>Choices/<font color="blue">Defaults</font></th>
|
||||
<th>Configuration</th>
|
||||
<th width="100%">Comments</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="1">
|
||||
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||
<b>criteria</b>
|
||||
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||
<div style="font-size: small">
|
||||
<span style="color: purple">raw</span>
|
||||
/ <span style="color: red">required</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
<div>The criteria used for validation of value that represents <code>data</code> options.</div>
|
||||
<div>This option represents the second argument passed in the lookup plugin For example <em>lookup(config_data, config_criteria, engine='ansible.utils.jsonschema'</em>), in this case the value of <em>config_criteria</em> represents this option.</div>
|
||||
<div>For the type of <code>criteria</code> that represents this value refer documentation of individual validate plugins.</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="1">
|
||||
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||
<b>data</b>
|
||||
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||
<div style="font-size: small">
|
||||
<span style="color: purple">raw</span>
|
||||
/ <span style="color: red">required</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
<div>A data that will be validated against <code>criteria</code>.</div>
|
||||
<div>This option represents the value that is passed to lookup plugin as first argument. For example <em>lookup(config_data, config_criteria, engine='ansible.utils.jsonschema'</em>), in this case <em>config_data</em> represents this option.</div>
|
||||
<div>For the type of <code>data</code> that represents this value refer documentation of individual validate plugins.</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="1">
|
||||
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||
<b>engine</b>
|
||||
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||
<div style="font-size: small">
|
||||
<span style="color: purple">string</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<b>Default:</b><br/><div style="color: blue">"ansible.utils.jsonschema"</div>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
<div>The name of the validate plugin to use.</div>
|
||||
<div>This option can be passed in lookup plugin as a key, value pair For example <em>lookup(config_data, config_criteria, engine='ansible.utils.jsonschema'</em>), in this case the value <em>ansible.utils.jsonschema</em> represents the engine to be use for data valdiation. If the value is not provided the default value that is <em>ansible.uitls.jsonschema</em> will be used.</div>
|
||||
<div>The value should be in fully qualified collection name format that is <em><org-name>.<collection-name>.<validate-plugin-name></em>.</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br/>
|
||||
|
||||
|
||||
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 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
|
||||
--------
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
- name: set facts for data and criteria
|
||||
set_fact:
|
||||
data: "{{ lookup('file', './validate/data/show_interfaces_iosxr.json')}}"
|
||||
criteria: "{{ lookup('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 <https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#common-return-values>`_, the following are the fields unique to this lookup:
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<table border=0 cellpadding=0 class="documentation-table">
|
||||
<tr>
|
||||
<th colspan="1">Key</th>
|
||||
<th>Returned</th>
|
||||
<th width="100%">Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="1">
|
||||
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||
<b>_raw</b>
|
||||
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||
<div style="font-size: small">
|
||||
<span style="color: purple">-</span>
|
||||
</div>
|
||||
</td>
|
||||
<td></td>
|
||||
<td>
|
||||
<div>If data is valid returns empty list</div>
|
||||
<div>If data is invalid returns list of errors in data</div>
|
||||
<br/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br/><br/>
|
||||
|
||||
|
||||
Status
|
||||
------
|
||||
|
||||
|
||||
Authors
|
||||
~~~~~~~
|
||||
|
||||
- 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.
|
|
@ -0,0 +1,175 @@
|
|||
.. _ansible.utils.validate_module:
|
||||
|
||||
|
||||
**********************
|
||||
ansible.utils.validate
|
||||
**********************
|
||||
|
||||
**Validate data with provided criteria**
|
||||
|
||||
|
||||
Version added: 1.0.0
|
||||
|
||||
.. contents::
|
||||
:local:
|
||||
:depth: 1
|
||||
|
||||
|
||||
Synopsis
|
||||
--------
|
||||
- Validate data with provided criteria based on the validation engine.
|
||||
|
||||
|
||||
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<table border=0 cellpadding=0 class="documentation-table">
|
||||
<tr>
|
||||
<th colspan="1">Parameter</th>
|
||||
<th>Choices/<font color="blue">Defaults</font></th>
|
||||
<th width="100%">Comments</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="1">
|
||||
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||
<b>criteria</b>
|
||||
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||
<div style="font-size: small">
|
||||
<span style="color: purple">raw</span>
|
||||
/ <span style="color: red">required</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
<div>The criteria used for validation of <code>data</code>. For the type of criteria refer documentation of individual validate plugins.</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="1">
|
||||
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||
<b>data</b>
|
||||
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||
<div style="font-size: small">
|
||||
<span style="color: purple">raw</span>
|
||||
/ <span style="color: red">required</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
<div>A data that will be validated against <code>criteria</code>. For the type of data refer documentation of individual validate plugins</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="1">
|
||||
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||
<b>engine</b>
|
||||
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||
<div style="font-size: small">
|
||||
<span style="color: purple">string</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<b>Default:</b><br/><div style="color: blue">"ansible.utils.jsonschema"</div>
|
||||
</td>
|
||||
<td>
|
||||
<div>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>.</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br/>
|
||||
|
||||
|
||||
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 task or environment variables.
|
||||
- The precedence the ``validate`` plugin configurable option is task variables followed by the environment variables.
|
||||
|
||||
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
- name: set facts for data and criteria
|
||||
set_fact:
|
||||
data: "{{ lookup('file', './validate/data/show_interfaces_iosxr.json')}}"
|
||||
criteria: "{{ lookup('file', './validate/criteria/jsonschema/show_interfaces_iosxr.json')}}"
|
||||
|
||||
- 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
|
||||
|
||||
|
||||
|
||||
Return Values
|
||||
-------------
|
||||
Common return values are documented `here <https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#common-return-values>`_, the following are the fields unique to this module:
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<table border=0 cellpadding=0 class="documentation-table">
|
||||
<tr>
|
||||
<th colspan="1">Key</th>
|
||||
<th>Returned</th>
|
||||
<th width="100%">Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="1">
|
||||
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||
<b>errors</b>
|
||||
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||
<div style="font-size: small">
|
||||
<span style="color: purple">list</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>when <code>data</code> value is invalid</td>
|
||||
<td>
|
||||
<div>The list of errors in <code>data</code> based on the <code>criteria</code>.</div>
|
||||
<br/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="1">
|
||||
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||
<b>msg</b>
|
||||
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||
<div style="font-size: small">
|
||||
<span style="color: purple">string</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>always</td>
|
||||
<td>
|
||||
<div>The msg indicates if the <code>data</code> is valid as per the <code>criteria</code>.</div>
|
||||
<div>In case data is valid return success message <em>all checks passed</em></div>
|
||||
<div>In case data is invalid return error message <em>Validation errors were found</em> along with more information on error is available.</div>
|
||||
<br/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br/><br/>
|
||||
|
||||
|
||||
Status
|
||||
------
|
||||
|
||||
|
||||
Authors
|
||||
~~~~~~~
|
||||
|
||||
- Bradley Thornton (@cidrblock)
|
||||
- Ganesh Nalawade (@ganeshrn)
|
|
@ -0,0 +1,171 @@
|
|||
.. _ansible.utils.validate_test:
|
||||
|
||||
|
||||
**********************
|
||||
ansible.utils.validate
|
||||
**********************
|
||||
|
||||
**Validate data with provided criteria**
|
||||
|
||||
|
||||
Version added: 1.0.0
|
||||
|
||||
.. contents::
|
||||
:local:
|
||||
:depth: 1
|
||||
|
||||
|
||||
Synopsis
|
||||
--------
|
||||
- Validate ``data`` with provided ``criteria`` based on the validation ``engine``.
|
||||
|
||||
|
||||
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<table border=0 cellpadding=0 class="documentation-table">
|
||||
<tr>
|
||||
<th colspan="1">Parameter</th>
|
||||
<th>Choices/<font color="blue">Defaults</font></th>
|
||||
<th>Configuration</th>
|
||||
<th width="100%">Comments</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="1">
|
||||
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||
<b>criteria</b>
|
||||
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||
<div style="font-size: small">
|
||||
<span style="color: purple">raw</span>
|
||||
/ <span style="color: red">required</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
<div>The criteria used for validation of value that represents <code>data</code> options.</div>
|
||||
<div>This option is passed to the test plugin as key, value pair For example <em>config_data is ansible.utils.validate(criteria=criteria</em>), in this case the value of <em>criteria</em> key represents this criteria for data validation.</div>
|
||||
<div>For the type of <code>criteria</code> that represents this value refer documentation of individual validate plugins.</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="1">
|
||||
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||
<b>data</b>
|
||||
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||
<div style="font-size: small">
|
||||
<span style="color: purple">raw</span>
|
||||
/ <span style="color: red">required</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
<div>A data that will be validated against <code>criteria</code>.</div>
|
||||
<div>This option represents the value that is passed to test plugin as check. For example <em>config_data is ansible.utils.validate(criteria=criteria</em>, in this case <em>config_data</em> represents this option.</div>
|
||||
<div>For the type of <code>data</code> that represents this value refer documentation of individual validate plugins.</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="1">
|
||||
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||
<b>engine</b>
|
||||
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||
<div style="font-size: small">
|
||||
<span style="color: purple">string</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<b>Default:</b><br/><div style="color: blue">"ansible.utils.jsonschema"</div>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
<div>The name of the validate plugin to use.</div>
|
||||
<div>This option can be passed in test plugin as a key, value pair For example <em>config_data is ansible.utils.validate(engine='ansible.utils.jsonschema', criteria=criteria</em>), in this case the value of <em>engine</em> key represents the engine to be use for data valdiation. If the value is not provided the default value that is <em>ansible.uitls.jsonschema</em> will be used.</div>
|
||||
<div>The value should be in fully qualified collection name format that is <em><org-name>.<collection-name>.<validate-plugin-name></em>.</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br/>
|
||||
|
||||
|
||||
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
|
||||
--------
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
- name: set facts for data and criteria
|
||||
set_fact:
|
||||
data: "{{ lookup('file', './validate/data/show_interfaces_iosxr.json')}}"
|
||||
criteria: "{{ lookup('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 Values
|
||||
-------------
|
||||
Common return values are documented `here <https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#common-return-values>`_, the following are the fields unique to this test:
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<table border=0 cellpadding=0 class="documentation-table">
|
||||
<tr>
|
||||
<th colspan="1">Key</th>
|
||||
<th>Returned</th>
|
||||
<th width="100%">Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="1">
|
||||
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||
<b>_raw</b>
|
||||
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||
<div style="font-size: small">
|
||||
<span style="color: purple">-</span>
|
||||
</div>
|
||||
</td>
|
||||
<td></td>
|
||||
<td>
|
||||
<div>If data is valid return <code>true</code></div>
|
||||
<div>If data is invalid return <code>false</code></div>
|
||||
<br/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br/><br/>
|
||||
|
||||
|
||||
Status
|
||||
------
|
||||
|
||||
|
||||
Authors
|
||||
~~~~~~~
|
||||
|
||||
- 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.
|
Loading…
Reference in New Issue