Closed jpiron closed 2 months ago
@jpiron Hi, can you try following code snippet?
-
hosts: localhost
connection: ansible.netcommon.network_cli
gather_facts: no
vars:
ansible_persistent_log_messages: True
some_xml: |
<?xml version="1.0" encoding="UTF-8"?>
<root>
<leaf>
<attribute>foobar</attribute>
</leaf>
</root>
tasks:
- ansible.builtin.set_fact:
test: "{{ (some_xml | ansible.utils.from_xml)}}"
- debug:
msg: "{{test.root.leaf}}"
Hi @ashwini-mhatre, using an intermediate variable works but this prevents from doing something like:
- hosts: localhost
connection: local
gather_facts: no
tasks:
- uri:
url: http://httpbin.org/xml
headers:
accept: "application/xml"
return_content: true
register: result
until: (result.content | ansible.utils.from_xml)['slideshow']['@author'] == 'Yours Truly'
retries: 3
delay: 2
It works by chaining the from_json
filter like the following:
- hosts: localhost
connection: local
gather_facts: no
tasks:
- uri:
url: http://httpbin.org/xml
headers:
accept: "application/xml"
return_content: true
register: result
until: (result.content | ansible.utils.from_xml | from_json)['slideshow']['@author'] == 'Yours Truly'
retries: 3
delay: 2
but it shouldn't be required if the goal is to provide the same behavior as from_yaml
and from_json
filters.
Concur, this should be fixed
Workaround is to use the from_yaml filter afterwards
SUMMARY
The
from_xml
filter returns a string instead of returning a python dictionary as its documentation reports and as thefrom_json
andfrom_yaml
filters do.ISSUE TYPE
COMPONENT NAME
from_xml
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
Ubuntu 20.04.3 LTS (Focal Fossa)
STEPS TO REPRODUCE
EXPECTED RESULTS
This should print
ACTUAL RESULTS