duplicated role execution..

I have defined three roles: A, B and C.

Using meta/main.yml, I have B depending on A, and C depending on A as well.

If I have the following:

  • hosts: group_test
    roles:
  • B
  • C

What happens is that the tasks associated to role A is executed twice. Is there any dedup mechanism to execute them only once?

Thanks…

Hi Xu -

Not that I have seen. I believe you will have duplicate tasks run.

John

Have a look at http://www.ansibleworks.com/docs/playbooks_roles.html#role-dependencies

There’s a meta variable to allow for duplicates, but AFAIK, that only works within one role dependency tree, while your case has two (B and C).
Maybe you can make that work with a role D which depends on B and C, not sure.

It’s possible that our duplicates filter needs a little tweaking, I’ll let James Cammarata reply here, though I will point out that it’s designed that roles with different parameters (i.e. dependencies with different parameters) do need to get re-evaluated.

You may want to have a look here: https://groups.google.com/d/msg/ansible-project/nd4wMLsb0Jw/7-svzpNpTIQJ

Nathan Howell has demonstrated a very nice approach which works very nice for me.