# Iterate through every group/host pair but won't work with 'groups'

**URL:** <https://forum.ansible.com/t/iterate-through-every-group-host-pair-but-wont-work-with-groups/26192>\
**Category:** Ansible Project\
**Created:** [December 2, 2017, 6:30pm UTC](https://forum.ansible.com/t/iterate-through-every-group-host-pair-but-wont-work-with-groups/26192 "2017-12-02T18:30:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![burton](https://avatars.discourse-cdn.com/v4/letter/b/8e7dd6/32.png) [@burton](https://forum.ansible.com/u/burton)\
**Post date:** [December 2, 2017, 6:30pm UTC](https://forum.ansible.com/t/iterate-through-every-group-host-pair-but-wont-work-with-groups/26192/1 "2017-12-02T18:30:21Z")

</div>

I don’t think Ansible will work with this scenario.

I want to iterate through every ansible role and host as a flat index.

Right now the groups variable is what I’m focused on. Which is:

group0:

- host0

- host1

group1:

- host2
- host3

I want to process it as:

group0, host0  
group0, host1  
group1, host2  
group1, host3

… but I don’t think this is possible. Is there a ‘flatten’ I can use?

with\_dict and with\_subelements won’t work.

with\_subelements complains that it expects a map with a key to iterate from.
