I have two lists:
inc_numbers: [A, B, C, D, E, F, G]
users:
- username: u1
status: active
- username: u2
status: active
- username: u3
status: active
- username: u4
status: active
Say the first list is tickets and the second list is users. How do I loop trough this? How do I assign these tickets in round-robin manner using Ansible?
I tried the following
- name: with_together -> loop
set_fact:
inc_user_map: "{{ inc_user_map|default([]) + [{ 'inc_numbers':item.0, 'users':item.1.username }] }}"
with_together:
- "{{ inc_numbers }}"
- "{{ users }}"`
- name: Nested loop
set_fact:
inc_sel: "{{ inc_sel|d([]) + [item|combine({'selection': selection})] }}"
loop: "{{ users }}"
vars:
username: "{{ item.username }}"
selection: "{{ inc_numbers|
zip(username)|
rejectattr('0', 'eq', '0') }}"
This does'nt give the desired output. It ends after completing single loop of users
Desired Output
A : u1
B : u2
C : u3
D : u1
E : u2
F : u3
G : u1
This example does what you ask and also allows you to exclude inactive users
Output:
Alternative version
Output: