Managing overlapping roles the "Ansible Way"

I’m having trouble figuring out the “Ansible way” of handling groups of servers with overlapping roles. By overlapping I mean that a playbook for a type of application server (e.g. haproxy) will deploy to servers in two different cloud environments, and each cloud environment has its own set of “common” configuration tasks. So each server gets one of two different common setup roles, plus one of N application roles.

/inventory/production:
[hap-a]
1.2.3.4 etc.

[hap-b]
2.3.4.5 etc.

[cloud1:children]
[hap-a]
[etc]

[cloud2:children]
[hap-b]
[etc]

/playbook.yml:

  • name: HAProxy
    hosts:
  • hap-a
  • hap-b
    user: somebody
    sudo: yes

roles:

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

  • { role: haproxy, tags: [ ‘haproxy’ ] }

My problem is that there need to be two “common” roles, one for cloud1 and one for cloud2. What’s the latest “best practice” for this? I’d like to avoid using “limit” in the command line so that I don’t have to execute the same playbook twice with different arguments. Thanks.

Generally geographic variance is dealt with by group variables.

“I’d like to avoid using “limit” in the command line so that I don’t have to execute the same playbook twice with different arguments.”

Then if you write the playbook to target both, it of course will, unless they are in different inventories, so you may want to split inventories.