# Complex loop question.

**URL:** <https://forum.ansible.com/t/complex-loop-question/18591>\
**Category:** Ansible Project\
**Created:** [June 24, 2015, 9:26am UTC](https://forum.ansible.com/t/complex-loop-question/18591 "2015-06-24T09:26:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nico\_K](https://avatars.discourse-cdn.com/v4/letter/n/46a35a/32.png) [@Nico\_K](https://forum.ansible.com/u/Nico_K)\
**Post date:** [June 24, 2015, 9:26am UTC](https://forum.ansible.com/t/complex-loop-question/18591/1 "2015-06-24T09:26:26Z")

</div>

Hi,

I’m looping over a set of repositories and storing them using ‘register’, for each of these repositories I’m listing the configuration directory and storing the results using register, so far so good.  
Now I’m trying to compare the results against a list of configuration files that should exist within that repository, but I can’t seem to get that done.

What I’m trying to do:

- name: check repos  
shell: ls -1 {{ path }}/{{ item.name }}/{{ config\_dir }}  
register: found  
with\_items: repositories

found, at this point contains ‘x’ repositories with ‘y’ files, y.stdout\_lines contains the files that were found for ‘x’.

The “cleanup” code I’m trying to write does something like:

- name: remove unmanaged  
file:  
path: …  
state: absent  
with\_together:
- repositories
- found.results
- item.1.stdout\_lines \<— these would be the actual file names  
when: item.2 not in configuration\_files

Sadly, this doesn’t seem to work… how is one supposed to deal with this?

Thanks,  
Nico

---

<div class="post-metadata">

**Author:** ![yunano](https://avatars.discourse-cdn.com/v4/letter/y/ecc23a/32.png) [@yunano](https://forum.ansible.com/u/yunano)\
**Post date:** [June 26, 2015, 12:47am UTC](https://forum.ansible.com/t/complex-loop-question/18591/2 "2015-06-26T00:47:49Z")

</div>

Hi,

You should use with\_subelements like:

- name: remove unmanaged  
file:  
path: …  
state: absent  
with\_subelements:
- found.results
- stdout\_lines  
when: item.1 not in configuration\_files

Thanks.

2015年6月24日水曜日 18時26分26秒 UTC+9 Nico K.:
