# Role included multiple times only seems to run once

**URL:** <https://forum.ansible.com/t/role-included-multiple-times-only-seems-to-run-once/25099>\
**Category:** Ansible Project\
**Created:** [July 26, 2017, 8:47pm UTC](https://forum.ansible.com/t/role-included-multiple-times-only-seems-to-run-once/25099 "2017-07-26T20:47:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Rathbone](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@Matthew\_Rathbone](https://forum.ansible.com/u/Matthew_Rathbone)\
**Post date:** [July 26, 2017, 8:47pm UTC](https://forum.ansible.com/t/role-included-multiple-times-only-seems-to-run-once/25099/1 "2017-07-26T20:47:02Z")

</div>

Hey guys,

So I have a project setup in the following way:

- requiring an external redis-server role
- my own role called redis-cluster-shard that uses redis-server as a dependency
- a playbook that applies this role twice to the same node. Like this:

`

- role: “rds-cache-shard”  
rds\_port: 7000
- role: “rds-cache-shard”  
rds\_port: 7001

`

The way a redis install is created is through the dependency in meta/main.ytml, which looks like this:  
`

dependencies:

- role: redis-server  
redis\_service\_name: “rds\_shard\_{{rds\_port}}”  
redis\_logfile: “/var/log/rds\_shard\_{{rds\_port}}.log”  
redis\_clustermode\_enabled: “yes”  
redis\_port: “{{rds\_port|int}}”  
redis\_save:
- 3600 1

`

The problem I’m having is that only one redis shard is created. IE the dependency only runs once, on the first rds-cache-shard include.

Am I doing something wrong? I’d expect the dependency tasks to run each and every time a role is included, especially as I’m scoping it with variables (rds\_port).

---

<div class="post-metadata">

**Author:** ![alikins](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@alikins](https://forum.ansible.com/u/alikins)\
**Post date:** [July 26, 2017, 9:20pm UTC](https://forum.ansible.com/t/role-included-multiple-times-only-seems-to-run-once/25099/2 "2017-07-26T21:20:10Z")

</div>

[http://docs.ansible.com/ansible/latest/playbooks\_roles.html#role-dependencies](http://docs.ansible.com/ansible/latest/playbooks_roles.html#role-dependencies)

“Roles dependencies are always executed before the role that includes them, and are recursive. By default, roles can also only be added as a dependency once - if another role also lists it as a dependency it will not be run again. This behavior can be overridden by adding to the file. For example, a role named ‘car’ could add a role named ‘wheel’ to its dependencies as follows:”

Does ‘allow\_duplictes: yes’ work?"

---

<div class="post-metadata">

**Author:** ![Matthew\_Rathbone](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@Matthew\_Rathbone](https://forum.ansible.com/u/Matthew_Rathbone)\
**Post date:** [July 26, 2017, 9:39pm UTC](https://forum.ansible.com/t/role-included-multiple-times-only-seems-to-run-once/25099/3 "2017-07-26T21:39:37Z")

</div>

Hey Adrian – thanks for your response!

I did about an hour of reading and playing around with dependencies and I figured it out:

I needed to add allow\_duplicates: yes to the role I was depending on, not my role. So I forked the redis-server role, added the statement, and it works!

Thanks for helping to point me in the right direction.

Matthew
