40 lines
1.1 KiB
YAML
40 lines
1.1 KiB
YAML
|
---
|
||
|
- name: Setup xml and expected json
|
||
|
ansible.builtin.set_fact:
|
||
|
data: "
|
||
|
<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\"><schemas><schema/></schemas></netconf-state>
|
||
|
"
|
||
|
output: {
|
||
|
"netconf-state": {
|
||
|
"@xmlns": "urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring",
|
||
|
"schemas": {
|
||
|
"schema": null
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- debug:
|
||
|
msg: "{{ data|ansible.utils.from_xml() }}"
|
||
|
|
||
|
- name: Integration tests with and without default engine as xmltodict and
|
||
|
assert:
|
||
|
that: "{{ output == item.test }}"
|
||
|
loop:
|
||
|
- test: "{{ data|ansible.utils.from_xml() }}"
|
||
|
- test: "{{ data|ansible.utils.from_xml('xmltodict') }}"
|
||
|
|
||
|
- name: Setup invalid xml as input to ansible.utils.from_xml.
|
||
|
ansible.builtin.set_fact:
|
||
|
data: "<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">"
|
||
|
|
||
|
- name: validate input xml
|
||
|
ansible.builtin.set_fact:
|
||
|
_result: "{{ data|ansible.utils.from_xml() }}"
|
||
|
ignore_errors: true
|
||
|
register: result
|
||
|
|
||
|
- assert:
|
||
|
that: "{{ msg in result.msg }}"
|
||
|
vars:
|
||
|
msg: "Error when using plugin 'from_xml': Input Xml is not valid"
|