# Using an outer list to access an inner list with with\_nested

**URL:** <https://forum.ansible.com/t/using-an-outer-list-to-access-an-inner-list-with-with-nested/17101>\
**Category:** Ansible Project\
**Created:** [December 18, 2014, 10:07pm UTC](https://forum.ansible.com/t/using-an-outer-list-to-access-an-inner-list-with-with-nested/17101 "2014-12-18T22:07:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ross\_Becker](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Ross\_Becker](https://forum.ansible.com/u/Ross_Becker)\
**Post date:** [December 18, 2014, 10:07pm UTC](https://forum.ansible.com/t/using-an-outer-list-to-access-an-inner-list-with-with-nested/17101/1 "2014-12-18T22:07:22Z")

</div>

So, I tried to do this, and found it didn’t work. I wasn’t terribly surprised, but it seems like a reasonable use-case.

The play is to be run on one host- a central server, and I have a list of groups that I want to perform actions for- for each host in each group.

The code looks something like this:

1. vars:

2. group\_list: [‘group1’, ‘group2’, ‘group3’]

3. my\_script: /some/script/foo.sh

4. 
5. tasks:

6. 
  - name: Nested task

7. command: ${my\_script} action-{{item.0}} “{{hostvars[item.1][‘some\_fact’]}}”

8. with\_nested:

9. 
  - group\_list

10. 
  - groups[item.0]

What happens is that ansible interprets “groups[item.0]” as a string and tries to iterate over it’s characters. Seems like a valid use case, but I can understand that re-evaluating the inner list on each outer-loop may be challenging.

It’s easily enough accomplished by unrolling the outer loop, but moderately annoying that I can’t reduce it to a nested loop.
