# Iterate over nested list inside a dict

**URL:** <https://forum.ansible.com/t/iterate-over-nested-list-inside-a-dict/8608>\
**Category:** Get Help\
**Created:** [September 18, 2024, 8:45pm UTC](https://forum.ansible.com/t/iterate-over-nested-list-inside-a-dict/8608 "2024-09-18T20:45:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HexaOrko](https://avatars.discourse-cdn.com/v4/letter/h/e5b9ba/32.png) [@HexaOrko](https://forum.ansible.com/u/HexaOrko)\
**Post date:** [September 18, 2024, 8:45pm UTC](https://forum.ansible.com/t/iterate-over-nested-list-inside-a-dict/8608/1 "2024-09-18T20:45:47Z")

</div>

hey, i have a little problem maybe someone can help.  
I want to generate lets encrypt certs with `ansible.builtin.acme_certificate`  
which seems to work, but i need to place the dns records, for this i use `community.general.netcup_dns`

My problem now is the result from acme\_certicate

```auto
    challenge_data_dns:
      _acme-challenge.example.net:
        - BKA2g7FqDE
        - SiUKqRuYI
      _acme-challenge.home.example.net:
        - gbYWTwtx3
      _acme-challenge.lab.example.net:
        - bAkdltnD3
        - efL6bGiTXI

```

I need to run netcup\_dns now multiple, 5 times in this example.

```auto
key:value
 _acme-challenge.example.net : BKA2g7FqDE
 _acme-challenge.example.net: SiUKqRuYI
_acme-challenge.home.example.net : gbYWTwtx3
_acme-challenge.lab.example.net : bAkdltnD3
_acme-challenge.lab.example.net : efL6bGiTXI

```

But the question is how to do this, i need somehow to loop over the single values in the list oh each key.

the with\_subelements module does not fit, because i’m not really able to predict the names after \_acme-challenge.

i has this litte example

```auto
- name: example
  hosts: all
  gather_facts: false
  strategy: linear
  vars:
    challenge_data_dns:
      _acme-challenge.example.net:
        - BKA2g7FqDE
        - SiUKqRuYI
      _acme-challenge.home.example.net:
        - gbYWTwtx3
      _acme-challenge.lab.example.net:
        - bAkdltnD3
        - efL6bGiTXI
  tasks:
    - name: debug out 
      debug:
        msg: "{{item}}"
      loop: "{{ challenge_data_dns | dict2items }}"
    
``
```

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [September 18, 2024, 8:59pm UTC](https://forum.ansible.com/t/iterate-over-nested-list-inside-a-dict/8608/2 "2024-09-18T20:59:15Z")

</div>

```auto
    - name: debug out 
      debug:
        msg: "{{ item.0.key }} : {{ item.1 }}"
      loop: "{{ challenge_data_dns|dict2items|subelements('value') }}"

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 18, 2024, 8:59pm UTC](https://forum.ansible.com/t/iterate-over-nested-list-inside-a-dict/8608/3 "2024-10-18T20:59:37Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
