I have a fairly complex set of Playbooks and imported Roles building an application platform. Everything is defined in a single hosts.ini
file, and extensive use is being made of groups to identify specialist server roles: web, database, search, etc.
However the overall platform supports two distinct instances of the application, and in some cases I need to set-up specific links between two of the four web nodes. For example, for the hosts list below I want to set-up gluster volumes between app1_node1 and app1_node2, and app2_node1 and app2_node2.
[web]
app1_node1
app1_node2
app2_node1
app2_node2
And have a playbook which does that, but only for two nodes at once. So if the hosts file also contains the following:
[webapp1]
app1_node1
app1_node2
[webapp2]
app2_node1
app2_node2
and the playbook is invoked with --limit=webapp1
(or webapp2) everything works fine.
But I'm not sure of the best way to build everything in one go. I could, for example, duplicate the playbook and have different hosts statements in each. But that doesn't seem like a good idea.
The best solution I've come up with is to have an intermediate playbook launcher that looks like this:
---
- name: PLAYBOOK playbook_launcher.yml
hosts: webapp1
tasks:
- name: Include playbook
import_playbook: theplaybook.yml
- hosts: webapp2
tasks:
- name: Include playbook
import_playbook: theplaybook.yml
With the actual playbook having a broader hosts statement.
---
- name: PLAYBOOK theplaybook.yml
hosts: web