Ansible setting vars from with_items

给你一囗甜甜゛ 提交于 2019-12-06 01:13:35

I ended up adding another task to set the query variables before the task that was using them.

- name: Setting Instance ID and query to use in looking up instance variables
  set_fact:
    inst_query:
      - inst_id: "{{ item.id }}"
        ip_query: "[?interface.attachment.instance_id=='{{ item.id }}'].interface.private_ip_address|[0]"
        sec_ip_query: "[?interface.attachment.instance_id=='{{ item.id }}'].interface.private_ip_addresses[?primary_address==false].[private_ip_address]"
  with_items:
    - "{{ ec2.tagged_instances }}"
- debug:
    msg: "{{ eni_dc.results|json_query(item.sec_ip_query) }}"
  with_items:
    - "{{ inst_query }}"

- name: Build VRF config
  template: >
    src=vrf.conf.j2
    dest={{ build_dir }}/{{ item.inst_id }}-vrf.conf.part
  with_items:
    - "{{ inst_query }}"
  vars:
    eni_dc_ip: "{{ eni_dc.results|json_query(item.ip_query) }}"
    eni_spoke_ip: "{{ eni_spoke.results|json_query(item.ip_query) }}"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!