Ansible – Combine Multiple Dictionaries with a List for Looping

ansibleansible-playbook

I have two dictionaries per host in ansible:

{ "rtt": [38,1,97] }

{ "site": ["A","B","C"] }

I want to now loop of a list or items, where i can reference the individual items like:

debug:
 msg: "{{ item.site }} is {{ item.rtt }}"
with_items: "{{ X }}"

How do i construct X ?

Best Answer

Is this probably what are you looking for? The play

- hosts: localhost
  vars:
    rtt: [38,1,97]
    site: ["A","B","C"]
  tasks:
    - debug:
        msg: "{{ item.0 }} is {{ item.1 }}"
      loop: "{{ site|zip(rtt)|list }}"

gives

  msg: A is 38
  msg: B is 1
  msg: C is 97