Hi
I’m struggling to achieve following behavior with serial, strategy, forks:
I have many typical nodes to update.
Process includes placing nodes into maintenance, it could take unpredictable time (hours).
I’m not allowed to offline more than defined number nodes at a time.
When I use serial parameter combined with free strategy ansible waits until every host in batch to be processed before taking next, so all process stucks.
I tried to switch from using serial to forks with free strategy, but in this case ansible doesn’t processing host by host with specified number of forks but performs tasks in random order, so number of offlined nodes could be more than forks number specified.
So I need to start process for defined number of hosts, when host processing is finished next host need to be started without waiting for all batch to finish, but overall number of concurrent hosts processed should be constant.
If i understood your use-case, probably the correct way is to use strategy free and serial, but you need to be sure that serial it will be less then forks used.
This because if serial is equal to forks, the queue used by ansible will be full before procede to next task.
You can see a real use case in this article on medium that explain very well strategy and serial with real use case:
With serial strategy ansible will not start to proceed new hosts until all hosts of current batch is not finished.
So if process stuck on some node ansible will not go further and will wait until current batch will be finished.
So,
If I understood you want to run X hosts in parallel, no more tha X and execute all tasks.
So, for example, 3 hosts in parallel, one finish very fast and the other two require much time. You want taht a new host will be process ed without wait the other 2 hosts finished, and so on.
I think that this will be possible only with strategy host_pinned (this strategy execute tasks on each host without interrupt in, and is different from free because you will wait the finish of play to host before leave new slot in the queue) and forks = Total hosto to be execute i parallel.
So, in case of my example you can set forks to 3 and strategy to host_pinned. In that way if host 1 will finish before host 2/3, will freeup one slot in queue and next host will be dtarted.
You can’t use serial because serial devide hosts in the play based on serial number, and consider those play as a separate play, this is why not works with strategy free and serial.
Moreover you can’t use strategy free because is like “random” in task execution (it’s possible that host 4 start before host 1,2,3 it’s finished).
Try with strategy host_pinned and forks = tot_number_of_parallel_host