# multiple loops in single TASK

**URL:** <https://forum.ansible.com/t/multiple-loops-in-single-task/36652>\
**Category:** Ansible Project\
**Tags:** kubernetes, rhel\
**Created:** [May 23, 2022, 4:43pm UTC](https://forum.ansible.com/t/multiple-loops-in-single-task/36652 "2022-05-23T16:43:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [May 23, 2022, 4:43pm UTC](https://forum.ansible.com/t/multiple-loops-in-single-task/36652/1 "2022-05-23T16:43:44Z")

</div>

I want to to install some packages to several almalinux hosts

- name: “docker=install”  
delegate\_to: “{{ item }}”  
dnf:  
name:
- ‘[https://download.docker.com/linux/rhel/8/source/stable/Packages/docker-ce-20.10.15-3.el8.src.rpm](https://download.docker.com/linux/rhel/8/source/stable/Packages/docker-ce-20.10.15-3.el8.src.rpm)’
- yum-utils
- device-mapper-persistent-data
- lvm2  
state: present  
loop:
- k8s-master
- k8s-node-1

this TASK works, but I was thinking whether I could put the packages into a loop also (which would result into 2 loops in one TASK)  
Can this be done? If so … ‘how’?

I tried to nest it like this

- name: “docker=install”  
delegate\_to: “{{ item }}”  
dnf:  
name: “{{ item }}”  
state: present  
loop:
- ‘[https://download.docker.com/linux/rhel/8/source/stable/Packages/docker-ce-20.10.15-3.el8.src.rpm](https://download.docker.com/linux/rhel/8/source/stable/Packages/docker-ce-20.10.15-3.el8.src.rpm)’
- yum-utils
- device-mapper-persistent-data
- lvm2  
loop:
- k8s-master
- k8s-node-1

but execution failed with an _“unsupported paramter for dnf module: loop”_ error

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [May 24, 2022, 1:08am UTC](https://forum.ansible.com/t/multiple-loops-in-single-task/36652/2 "2022-05-24T01:08:57Z")

</div>

This is not possible.  
Also, why would you want to ‘nest’ the packages?

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [May 24, 2022, 7:50am UTC](https://forum.ansible.com/t/multiple-loops-in-single-task/36652/3 "2022-05-24T07:50:31Z")

</div>

ok, thx good point, maybe that’s just me trying to abstract things over the top

---

<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:** [May 24, 2022, 1:59pm UTC](https://forum.ansible.com/t/multiple-loops-in-single-task/36652/4 "2022-05-24T13:59:26Z")

</div>

You cannot have multiple loops per task (aside from already existing  
host loop) BUT you can basically get the same thing by making the data  
result into the same thing you would have in that case or you can loop  
over an include that has the task with it's own loop.
