Created
February 15, 2021 16:36
-
-
Save ganeshrn/97909f5aacda5212a7cdf146eccde149 to your computer and use it in GitHub Desktop.
xml to json using xmltodict
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: localhost | |
connection: local | |
gather_facts: false | |
tasks: | |
- name: set sample xml string | |
set_fact: | |
xml_var: | | |
<a> | |
<foo>test</foo> | |
<bar>test1</bar> | |
</a> | |
- name: convert xml to json | |
ansible.utils.cli_parse: | |
text: "{{ xml_var }}" | |
parser: | |
name: ansible.utils.xml | |
register: json_var | |
- name: "check json value" | |
assert: | |
that: "{{ item }}" | |
with_items: | |
- "{{ json_var['parsed']['a']['bar'] == 'test1' }}" | |
- "{{ json_var['parsed']['a']['foo'] == 'test' }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment