遍历嵌套字典

时间:2019-02-25 19:34:29

标签: ansible ansible-2.x

下面是我需要遍历的嵌套字典:

clients:
  apache:
    - apa01-pco.web.vpn
    - apa02-pco.web.vpn

  mailout:
    - zmo11-pco.mail.vpn
    - zmo12-pco.mail.vpn

我需要通过遍历上面的字典来注册如下所示的变量:

必需的输出:

clients:
  apache:
    - 10.8.12.61
    - 10.8.12.62

  mailout:
    - 10.5.13.21
    - 10.5.13.22

基本上,这个想法是用各自的IP替换主机名。到目前为止,我已经编写了以下任务:

- name: Setting log-client IPs
  set_fact:
    ip_addr: '{{ lookup("dig", item.1) }}'
  loop: "{{ clients | dict2items | subelements('value') }}"
  register: dig_results

这显然没有达到要求,因为它仅生成IP列表,而不生成所需的输出。

谢谢。

0 个答案:

没有答案
相关问题