xml module don't keep the xml nested child structure in the result

16 views
Skip to first unread message

Bruno1

unread,
Sep 12, 2021, 9:43:58 AM9/12/21
to Ansible Project
Hi,
I'm trying to use the xml module to find a xml block.
The xpath find the block, but all nested child structure is removed, I.E all data is at same level after.
Has anyone any ideas what is missing?
Wrong module to use?

  tasks:
      - name: manage xml block
        xml:
          path: "output/{{ inventory_hostname }}_get_config.xml"
          xpath: /root/groups[name="test"]//*
          content: text
        register: test

      - name: Print result xml
        debug:
          msg: "{{ test.matches}} "


Dick Visser

unread,
Sep 12, 2021, 10:11:01 AM9/12/21
to ansible...@googlegroups.com
Hard to say without any actual xml content

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/64b258ce-b464-460a-b5d4-d06551f7ef73n%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Bruno1

unread,
Sep 12, 2021, 11:15:33 AM9/12/21
to Ansible Project
Hi,
Here  comes an example:

    <root>
            <groups>
                <name>test</name>
                <security>
                    <policies>
                        <global>
                            <policy>
                                <name>test</name>
                                <match>
                                    <source-address>any</source-address>
                                    <destination-address>any</destination-address>
                                    <application>any</application>
                                </match>
                                <then>
                                    <permit>
                                    </permit>
                                </then>
                            </policy>
                        </global>
                    </policies>
                </security>
            </groups>
            <groups>
                <name>test2</name>
                <chassis>
                    <cluster>
                        <redundancy-group>
                            <name>0</name>
                            <node>
                                <name>0</name>
                                <priority>254</priority>
                            </node>
                            <node>
                                <name>1</name>
                                <priority>128</priority>
                            </node>
                        </redundancy-group>
                    </cluster>
                </chassis>
            </groups>
    </root>

The output is :
        "matches": [
            {
                "name": "test"
            },
            {
                "security": null
            },
            {
                "policies": null
            },
            {
                "global": null
            },
            {
                "policy": null
            },
            {
                "name": "test"
...
...
..
Reply all
Reply to author
Forward
0 new messages