suggestions to make my master playbook simpler

Hi,

I have a master playbook to deploy 10 different group servers per region but would like to make things simpler. As you can see the vars_files section and handlers bellow is the same on all groups, the only things that changes is the “hosts” line and the specific role for each group type. I could create 10 separate files for every group server and call all files from a master playbook using the “- include” statement but what I would really like to avoid here is to have to define all those same vars_files and handlers for each group.

Is it possible to define all vars_files and handlers in a single place ?

“”"

  • hosts: A-group-servers
    user: root
    vars_files:

Global defaults

  • group_vars/all.yml

Password & Access keys

  • private_vars/prod-secret-vars.yml

Enviroment values

  • group_vars/prod-eu-west.yml
    handlers:

  • include: roles/common/handlers/main.yml
    roles:

  • { role : common , tags: [ ‘common-role’ ] }

  • { role : visitor-profile , tags: [ ‘a-group-role’ ] }
    post_tasks:

  • include: roles/common/tasks/couchbase-rebalance.yml

  • hosts: B-group-servers
    user: root
    vars_files:

Global defaults

  • group_vars/all.yml

Password & Access keys

  • private_vars/prod-secret-vars.yml

Enviroment values

  • group_vars/prod-eu-west.yml
    handlers:
  • include: roles/common/handlers/main.yml
    roles:
  • { role : common , tags: [ ‘common-role’ ] }
  • { role : visitor-profile , tags: [ ‘b-group-role’ ] }

.
.
.
.
.
“”"

Regards,
Nicolas.

You could define a group for prod-eu-west. You can include other groups with

[prod-eu-west:children]
A-group-servers roletag=a-group-role
B-group-servers roletag=b-group-role

(untested)
Described here:
https://github.com/ansible/ansible/blob/devel/docsite/rst/intro_inventory.rst#groups-of-groups-and-group-variables
(I have no idea where this hides in the doc so I’m linking the github docsite)

HTH