role dependencies, with variables as arguments, called from multiple roles

I’d like for roles which configure Node apps, to generate some snippets for an HAProxy config. I’d like to be able to call the same role dependency, app_snippet, in a generalized way, across many apps (app1, app2, etc.). However, the dependency executes once, even though I am using the allow_duplicates: yes in the meta/main.yml for each app.

In short, I’d like role app_snippet to be completely data-driven and called as a dependency of each app, and executed once for each app, using vars from the calling app role.

Am I missing something fundamental with Variable scoping? Or is this an anti-pattern in Ansible? The allow_duplicates: yes boolean seems to only be in the scope of the calling app role, not global across roles.

PLAYBOOK: apps.yml

  • name: install apps
    hosts: webservers
    roles:
  • { role: app1 }
  • { role: app2 }

ROLES:
roles/app1/
roles/app2/
roles/app_snippet/

ROLE appN: (i.e. app1 and app2 are mostly the same, for the purposes of role dependency)

roles/appN/vars/main.yml

Hi,

I’m seeing the same problem and have a very similar use case.

allow_duplicates = yes doesn’t seem to be working as I would expect. Unsure if its a bug or I have misunderstood how it works

James