# Looking for ideas

**URL:** <https://forum.ansible.com/t/looking-for-ideas/13285>\
**Category:** Ansible Project\
**Created:** [August 12, 2013, 9:03pm UTC](https://forum.ansible.com/t/looking-for-ideas/13285 "2013-08-12T21:03:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jesse\_Keating](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@Jesse\_Keating](https://forum.ansible.com/u/Jesse_Keating)\
**Post date:** [August 12, 2013, 9:03pm UTC](https://forum.ansible.com/t/looking-for-ideas/13285/1 "2013-08-12T21:03:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [August 12, 2013, 9:06pm UTC](https://forum.ansible.com/t/looking-for-ideas/13285/2 "2013-08-12T21:06:55Z")

</div>

“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.

---

<div class="post-metadata">

**Author:** ![Jesse\_Keating](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@Jesse\_Keating](https://forum.ansible.com/u/Jesse_Keating)\
**Post date:** [August 12, 2013, 10:10pm UTC](https://forum.ansible.com/t/looking-for-ideas/13285/3 "2013-08-12T22:10:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 12, 2013, 11:14pm UTC](https://forum.ansible.com/t/looking-for-ideas/13285/4 "2013-08-12T23:14:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jesse\_Keating](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@Jesse\_Keating](https://forum.ansible.com/u/Jesse_Keating)\
**Post date:** [August 12, 2013, 11:50pm UTC](https://forum.ansible.com/t/looking-for-ideas/13285/5 "2013-08-12T23:50:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kahlil.hodgson](https://avatars.discourse-cdn.com/v4/letter/k/b9bd4f/32.png) [@kahlil.hodgson](https://forum.ansible.com/u/kahlil.hodgson)\
**Post date:** [August 12, 2013, 11:56pm UTC](https://forum.ansible.com/t/looking-for-ideas/13285/6 "2013-08-12T23:56:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 13, 2013, 12:32am UTC](https://forum.ansible.com/t/looking-for-ideas/13285/7 "2013-08-13T00:32:33Z")

</div>

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?
