I have a relatively standard HA deployment, where I have several regions each with their own load balancer and several hosts in each region.
What I want to do is be able to do a normal ansible-playbook run, and have it run all regions in parallel, but each host within a region serially. Using the below (fake) inventory, paris01, fra01, and lon01 start at the same time. after paris01 finishes, paris02 doesn’t care what the state of fra* and lon* are, but paris03 won’t start until paris02 is done.
I’ve found a lot of queries about this over the years, but no satisfactory answers. I am aware of setting serial:1 and then limiting my playbook execution to specific inventory groups, but would prefer not to do that (as it is annoying).
No; another option would be a playbook with multiple plays. The first play would select the first host from each of the three regional groups, dynamically create a group containing those three hosts, and likewise for each of the N-th hosts.
Then [hand-waving here] you would run your “real” play successively on each of these groups of hosts. Somehow.
Assuming it’s possible and you work out the details, you’ll end up with something rather complicated to read but which functionally is equivalent to running three ansible-playbook instances (as per my prior post). You could stand up AWX or AAP and schedule three jobs, one per region, which is great if you need the functionality that AWX/AAP provide for additional things. But it’s a lot of stuff to set up if the only point is to avoid a half-dozen lines of bash.
I can see the appeal of expressing that functionality in one glorious YAML expression. But the permutations on hosts, groups, and play strategies is already complicated enough. If you made ansible-playbook “recursively parallel” so to speak, I fear the complexity would far outweigh the practical benefits.
Not to rule out the possibility that some obscure combination of Ansible options that I haven’t thought of might provide the functionality you’re after, but I’m skeptical. Maybe a custom strategy plugin could pull it off?
thanks a lot @kks and @utoddl, a custom strategy might end up doing the trick.
Thankfully right now it’s only 2 hosts each spread over two regions, so serial:1 is acceptable for now. But the medium-term goal is something like 40 regions, which gets quite intensive.
Is the play(book) identical for all of the host groups? If that is the case, or if it can be made like that, there is a trick with throttle task level keyword that I used to achieve this. Now, in my defense, it was implemented for a single task only. I’m not sure if it will work as expected if applied to a block of tasks. Also, it requires some clever ordering of hosts in the inventory.