multiple loops in single TASK

25 views
Skip to first unread message

dulh...@mailbox.org

unread,
May 23, 2022, 12:44:01 PM5/23/22
to ansible...@googlegroups.com
I want to to install some packages to several almalinux hosts

- name: "docker=install"
delegate_to: "{{ item }}"
dnf:
name:
- 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:
- 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

Dick Visser

unread,
May 23, 2022, 9:09:22 PM5/23/22
to ansible...@googlegroups.com
This is not possible.
Also, why would you want to 'nest' the packages?

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/749db923-40f4-f9c8-9dfc-9ea0e81ea216%40mailbox.org.
--
Sent from Gmail Mobile

dulh...@mailbox.org

unread,
May 24, 2022, 3:50:53 AM5/24/22
to ansible...@googlegroups.com


On 24.05.22 03:08, Dick Visser wrote:
This is not possible.
ok, thx

Also, why would you want to 'nest' the packages?
good point, maybe that's just me trying to abstract things over the top


Brian Coca

unread,
May 24, 2022, 10:00:33 AM5/24/22
to Ansible Project
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.



--
----------
Brian Coca

Reply all
Reply to author
Forward
0 new messages