|
I have a Java program (/workspace/Task), I want to run it in several Linux machines (m1, m2, m3, mn).
I need to run a program Task on machines one by one. In other words, I want to run the Task on m1, when it initials, I run the program on m2,… etc. Meaning that the Task must NOT start on new machine until it completely initials on the previous machine.
The following is steps that I want to create using Ansible:
machines (m1, m2, m3, …, mn)
task=/workspace/task
for i=0 to i=n do
run task on mi
end for
Again, it needs to starts deploying the task on new machines after the previous one is completed.
Can I achieve above request using Ansible? if yes how can I start?
Thank you
Ibrahim
|
You can use the ‘serial’ keyword to run on one machine at a time:
`
- hosts: m1,m2,m3,…
serial: 1
tasks:
command: /workspace/task
`
You might also want to use ‘max_fail_percentage’ to stop if there’s too many failures.
As I am new in Ansible, is the keyword “serial” be found in Ansible?
https://docs.ansible.com/ansible/playbooks_delegation.html#rolling-update-batch-size
serial let’s you choose how many hosts will execute a task in parallel. So serial=1 ensures that only one host is being processed at a time.
So forks (defaults to 5) controls how many hosts in parallel you'll
reach per task, serial controls the number of hosts you process per
play per batch (defaults to all hosts).
Serial can be a bit confusing, let me try to make it clear with actual numbers:
Normally Ansible will run a task on 5 in parallel, then do next 5 and
so on until all hosts have done that task, then move to the next task
and so on until the end of the play.
serial 10 and forks 5, will run the task on 5 hosts at a time but will
move to the next task after 10 hosts, so it will run the play for 10
hosts, parallelizing 5 hosts/tasks at a time, once the first 10 hosts
are done, the next 10 hosts start the play.