# How to nested loop with list

**URL:** <https://forum.ansible.com/t/how-to-nested-loop-with-list/37025>\
**Category:** Ansible Project\
**Created:** [August 23, 2022, 6:21pm UTC](https://forum.ansible.com/t/how-to-nested-loop-with-list/37025 "2022-08-23T18:21:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jin\_M](https://avatars.discourse-cdn.com/v4/letter/j/54ee81/32.png) [@Jin\_M](https://forum.ansible.com/u/Jin_M)\
**Post date:** [August 23, 2022, 6:21pm UTC](https://forum.ansible.com/t/how-to-nested-loop-with-list/37025/1 "2022-08-23T18:21:11Z")

</div>

I am looking for a solution to handle something like this:

roles:

- role1
- role2

configuration:  
role:  
role1:

- domain: “\*”  
limit\_type: hard  
limit\_item: nproc  
value: 40960

- domain: “\*”  
limit\_type: soft  
limit\_item: nproc  
value: 40960

- name: setup role-specific limits  
pam\_limits:  
dest: /etc/security/limits.d/user.conf  
domain: “{{ pam\_limits[‘role’][item][‘domain’] }}”  
limit\_type: “{{ pam\_limits[‘role’][item][‘limit\_type’] }}”  
limit\_item: “{{ pam\_limits[‘role’][item][‘limit\_item’] }}”  
value: “{{ pam\_limits[‘role’][item][‘value’] }}”  
when: (‘role’ in pam\_limits) and (item in pam\_limits[‘role’])  
with\_items: “{{ roles }}”

I see an error: The task includes an option with an undefined variable. The error was: ‘list object’ has no attribute ‘domain’. Looks like pam\_limits[‘role’][item] is the list and needs to be flattened.

Thank you.
