question about loop/with_items

hi,

say i have in hosts file 2 nodes.

[nodes]
server1
server2

in a playbook, we do some loop for tasks.

  • hosts: nodes

    with_items : [‘apple’,‘banana’]

ansible will run it like in the below order:

server1 : apple
server2: apple
server1: banana
server2: banana

what if i want to run in this order?

server1: apple
server1: banana
server2: apple
server2: banana

Is there a good approach for this?

Check out serial, serial: 1 on the play will give you that.

Hey Kai,

thanks… do you know why if its 1 server at a time(serial: 1), the play will behave this way?

The documentation explains this pretty well
https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html