Skip to content

Instantly share code, notes, and snippets.

@ganeshrn
Created February 15, 2021 16:36
Show Gist options
  • Save ganeshrn/97909f5aacda5212a7cdf146eccde149 to your computer and use it in GitHub Desktop.
Save ganeshrn/97909f5aacda5212a7cdf146eccde149 to your computer and use it in GitHub Desktop.
xml to json using xmltodict
---
- 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