Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Ansible manages all hosts in parallel or just five? (-f and :serial)

I read this two ansible docs:

ansible-playbook -f --> Statement 1

ansible-playbook :serial --> Statement 2

and I found this two statements:

Statement 1

-f <FORKS>, --forks <FORKS>

specify number of parallel processes to use (default=5)

Statement 2

Rolling Update Batch Size. By default, Ansible will try to manage all of the machines referenced in a play in parallel. For a rolling update use case, you can define how many hosts Ansible should manage at a single time by using the serial keyword:

Question

What's correct? Does ansible uses all hosts at once or just 5? Or is maybe 5 just the default value of the -f parameter?

Thanks for clarifying that!

Cheers

like image 347
DiViNe Avatar asked Jan 07 '19 15:01

DiViNe


1 Answers

--forks sets number of hosts on which the current task is executed simultaneously (see Ansible Configuration Settings)

serial sets number (or percentage/fraction) of hosts on which the playbook is run first, and after succesful completion, it is applied on another number of hosts (see Delegation, Rolling Updates, and Local Actions)

Example:

With settings:

  • Inventory with host[1-7]
  • Playbook with task1 and task2
  • --fork 2
  • serial: 3

The procedure is:

  1. run task1 on host1 and host2
  2. run task1 on host3
  3. run task2 on host1 and host2
  4. run task2 on host3
  5. finish playbook run on host[1-3]
  6. run task1 on host4 and host5
  7. run task1 on host6
  8. run task2 on host4 and host5
  9. run task2 on host6
  10. finish playbook run on host[4-6]
  11. run task1 on host7
  12. run task2 on host7
  13. finish playbook run on host7

Because:

  • you are executing one task on 2 hosts at a time at most (--fork)
  • you are executing whole playbook on 3 hosts at a time at most (serial)
like image 112
Halis Avatar answered Sep 18 '22 04:09

Halis