Our inventory is divided up into multiple environments, that is when we execute our inventory plugin, we provide an ENV_NAME environment variable to tell the plugin which environment to load.
Within each environment there are a number of logical groupings, we'll call these "cells". Each environment has 1 or more cell, and they get added semi-frequently so there isn't necessarily a hard coded list of them (although it is discoverable at run-time). My inventory plugin creates a group for each of those cells, that has other child-groups within.
My need is to run a couple tasks. A torrent task and a stop torrent task. These tasks need to run in parallel within the cell, but serially through the list of cells. That is I have to torrent and then stop torrenting in cell1 before doing anything in cell2, and then cell3, etc...
I'm looking for ways to express this in a playbook and falling short. I know I could use a shell script to loop over calling ansible-playbook providing a different --limit value each time but that feels inelegant.
So I ask you, fellow Ansible users, do you have any ideas?
Not sure it would be more elegant but having ansible-playbook calling
ansible-playbook ....
That is the top level playbook do all the inventory stuff to calculate
cell1, cell2 , .. as host groups
and then having a loop task that call ansible-playbook (via shell
command) from the local_host doing
the effective work and passing the {{ current_cell }} as a set of host
for a play in the second level playbook
so a way to simulate a loop over a play (the host mapping layer) with
the capability to change the play
parameters (hosts in your case)
Not sure Michael would like to see this being materialized as a
'playbook' module
Ansible’s CLI doesn’t really make sense to have the CLI do this IMHO, because the output would be a mess with so many different things happening in parallel, so it does one play at a time normally.
I thought over this yesterday evening, and was trying to figure out a way to do it with playbooks, and could not come to anything that made sense. But I realized I was only looking at the problem from 1 angle. ansible provides more than ansible-playbook, and in fact I think the only way to achieve this is to use the Ansible Python API, which ansible-playbook utilizes.
You could, probably with minimal changes, convert ansible-playbook, to loop it’s execution of the playbook multiple times over the groups of an inventory.
Just some thoughts, but I am sure it could be done somewhat easily. However without some additional work to log the tasks and such, it will really just look like you have run ansible-playbook multiple times.