Ansible: how to parse XML values from URI (REST) xml output

烈酒焚心 提交于 2020-05-31 05:58:31

问题


i have below Ansible playbook to access my server and fetch data using REST API mechanism, and i am able to get output XML format, but struggling to parse only specific values from that output.

Ansible Playbook - debug

- debug:
    var: steering

- debug: msg="{{ steering | regex_findall('<name>(.*?)</name>') }}"

- debug: msg="{{ steering | regex_findall('<value>(.*?)</value>') }}"

Output of last 2 debug responses

TASK [debug] ****************************************************************************************************************************
ok: [localhost] => {
    "msg": [
        "ip-address",
        "start-port",
        "end-port",
        "realm-id",
    ]
}

TASK [debug] ****************************************************************************************************************************
ok: [localhost] => {
    "msg": [
        "10.10.10.12",
        "7000",
        "15000",
        "Core",

How can i fetch only name & values together instead of separate debug responses (by modifying regex_findall).. or else please help if there is any possibility to merge last debug responses to get name & values together.

Expected Output

"ip-address - 10.10.10.12",
"start-port - 7000",
"end-port - 15000",
"realm-id - Core"

Please help..

thanks in advance.

来源:https://stackoverflow.com/questions/60023625/ansible-how-to-parse-xml-values-from-uri-rest-xml-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!