I have a need…
I need to run the same set of tasks across groups of hosts, however the groups of hosts are dynamic, dynamic per environment I'm running in. I'd like to not resort to a wrapper script around Ansible to discover the groups and bash loop over calling ansible-playbook if at all possible, so I'm looking for ideas on how to do this with includes.
Any ideas?
I already have playbook contents to /discover/ the groups to loop over, some environments will have ['c0001', 'c0002', 'c0003',] and some will have ['c0001', 'h0001', 'a0001'…]. Some go from c0001 through c0011, some are only a couple. But I can discover which ones exist and wind up with a variable that has this information, and I'm already doing some tasks that loop over each group to do something locally based on the group name. Just hoping I can extend this to include a set of tasks or a set of plays, one group at a time.
-jlk
“I need to run the same set of tasks across groups of hosts, however the groups of hosts are dynamic, dynamic per environment I’m running in.”
It seems like this is a function of your inventory script to assign groups appropriately, but perhaps I’m missing something.
Let me explain a bit more.
Within a group of systems I need to start a torrent, then stop a torrent. I need to do this in parallel within a group, but /serially/ across all the groups. Depending on which environment I point this at (an option to the inventory plugin) the names of the groups and how many there are will change.
-jlk
Sounds like if you want parallel across groups and then serially across all the groups it is just:
-
hosts: group1
roles:
-
blarg
-
hosts: group2
roles:
-
blarg
-
hosts: group3
roles:
-
blarg
So pretty straightforward playbook that will hit each group one after another.
If your group names change based on environment and it is just a prefix, you can pass in the prefix with -e as the “hosts:” line is templated with -e values.
–Michael
Group prefix (well group whole name really) and the number of groups change per-environment.
I really hope I don't have to do a bash loop around calls to ansible-playbook, but it's looking that way
-jlk
You could template the ansible playbook itself and use a local_action
to run ansible-playbook on the result
(Yes I am joking, ... I think)
K
Kahlil (Kal) Hodgson GPG: C9A02289
Head of Technology (m) +61 (0) 4 2573 0382
DealMax Pty Ltd (w) +61 (0) 3 9008 5281
Suite 1415
401 Docklands Drive
Docklands VIC 3008 Australia
"All parts should go together without forcing. You must remember that
the parts you are reassembling were disassembled by you. Therefore,
if you can't get them together again, there must be a reason. By all
means, do not use a hammer." -- IBM maintenance manual, 1925
You could just code generate the (rather basic) playbook, I guess.
Thankfully it’s data so no need to rely on templating – just dump the model as YAML?