question about loop/with_items

23 views
Skip to first unread message

Edmund Cheng

unread,
May 11, 2018, 3:33:00 AM5/11/18
to Ansible Project
hi,

say i have in hosts file 2 nodes.

[nodes]
server1
server2

in a playbook, we do some loop for tasks.

- hosts: nodes
  <some task>
  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?

Kai Stian Olstad

unread,
May 11, 2018, 4:11:21 AM5/11/18
to ansible...@googlegroups.com
Check out serial, serial: 1 on the play will give you that.

--
Kai Stian Olstad

Edmund Cheng

unread,
May 11, 2018, 4:39:25 AM5/11/18
to Ansible Project
Hey Kai,

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

Kai Stian Olstad

unread,
May 11, 2018, 5:25:10 AM5/11/18
to ansible...@googlegroups.com
On 11.05.2018 10:39, Edmund Cheng wrote:
> 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

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages