Ansible如何迭代多维数据

时间:2018-05-16 20:19:21

标签: ansible

遇到循环问题。尝试循环遍历aws查询的结果,以获取ALB的目标组的TargetHealth状态。看来我需要一个嵌套的循环结构,但无法弄明白。

任务:

 - debug:
      msg: "{{ item.stdout }}"
   loop: "{{ arns.results }}"

输出

TASK [debug] *******************************************************************
ok: [localhost] => (item=None) => 
  msg:
    TargetHealthDescriptions:
    - HealthCheckPort: '8091'
      Target:
        Id: i-00ceb9a71c24eaa5b
        Port: 8091
      TargetHealth:
        State: healthy
ok: [localhost] => (item=None) => 
  msg:
    TargetHealthDescriptions:
    - HealthCheckPort: '8090'
      Target:
        Id: i-00ceb9a71c24eaa5b
        Port: 8090
      TargetHealth:
        State: healthy

我如何获得'州'?

1 个答案:

答案 0 :(得分:0)

尝试 -

- debug:
      msg: "{{ item }}"
  when: '' != ( item | regex_search( 'State: ' ) )
  with_items: "{{ arns.results.stdout_lines }}"

另一方面,我可能会在创建此输出的命令中尝试grep ...