【问题标题】:Loop over a list from xml results in Ansible遍历来自 xml 的列表会导致 Ansible
【发布时间】:2020-04-28 12:35:16
【问题描述】:

我有这样的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】:

    您可以像下面这样循环遍历列表:

      - name: xml tags
        xml:
          xmlstring: "{{ item.xml }}"
          xpath: "/rpc-reply/lldp-remote-system-name"
          content: text
        loop: "{{ model.results }}"
    

    【讨论】:

      猜你喜欢
      • 2022-06-22
      • 2020-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多