从xml遍历列表会导致Ansible

问题描述 投票:0回答:1

我有这样的xml回复:

"model": {
    "results": [ {"item": "A", "xml":"...."}, {"item": "B", "xml":"...."} ]
 }

我正在尝试遍历结果列表并获取元素'xml'。现在我正在做这样的事情:

- name: Retrieve xml tags 
  xml:
    xmlstring: "{{ item.string }}"
    xpath: "{{ item.path }}"
    content: text
  loop:  
    - { path: "/rpc-reply/lldp-remote-system-name", string: "{{ model.results[].xml }}" }

但是这不起作用。我也尝试过:

model.results[*].xml,但这是错误的。

并且我试图在其中添加第二个循环,但是我什么也没得到。有什么建议吗?

xml loops ansible
1个回答
1
投票

您可以如下循环浏览列表:

  - name: xml tags
    xml:
      xmlstring: "{{ item.xml }}"
      xpath: "/rpc-reply/lldp-remote-system-name"
      content: text
    loop: "{{ model.results }}"
© www.soinside.com 2019 - 2024. All rights reserved.