# Role Dependency Not Being Executed

**URL:** <https://forum.ansible.com/t/role-dependency-not-being-executed/16980>\
**Category:** Ansible Project\
**Created:** [December 6, 2014, 6:17pm UTC](https://forum.ansible.com/t/role-dependency-not-being-executed/16980 "2014-12-06T18:17:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jamal\_B](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@Jamal\_B](https://forum.ansible.com/u/Jamal_B)\
**Post date:** [December 6, 2014, 6:17pm UTC](https://forum.ansible.com/t/role-dependency-not-being-executed/16980/1 "2014-12-06T18:17:09Z")

</div>

Hi I have run into an issue where I’m not sure if it’s a bug in Ansible or just my lack of understand how roles are activated. Using Ansible 1.7.2, I have a playbook defined as such:

app/site.yml  
app/roles/core/tasks/main.yml  
app/roles/app-common/tasks/main.yml  
app/roles/app-compA/meta/main.yml → contains a dependency on app-common

app/roles/app-compA/tasks/main.yml  
app/roles/app-compB/meta/main.yml → contains a dependency on app-common

app/roles/app-compB/tasks/main.yml

Where site.yml activates roles like such:

- hosts: all  
vars:  
home: /usr/local/app  
release: “{{ lookup(‘env’,‘RELEASE’) }}”  
group: “{{ lookup(‘env’,‘GROUP’) }}”

roles:

- core

# Component Specific Stuff

- { role: app-compA, when: group== ‘compA’ }

- { role: app-compB, when: group== ‘compB’ }

When I run the playbook like so:  
export GROUP=compA  
ansible-playbook site.yml -c local

The roles core, app-common & app-compA execute like expected.

However when I run the playbook like so:  
export GROUP=compB  
ansible-playbook site.yml -c local

Only the roles core and app-compB are executed and the app-common role is not executed. Shouldn’t the app-common role also be executed in this case? Is this a bug or have I mis-understood how roles are executed when role dependencies exists? My intent was to minimize the duplication of the tasks defined in app-common that are required by the app-compA & app-compB roles, so if there is another way to do this I’m all ears.

Thanks

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [December 7, 2014, 9:38pm UTC](https://forum.ansible.com/t/role-dependency-not-being-executed/16980/2 "2014-12-07T21:38:51Z")

</div>

Hard to see with the way it’s written above, do you perhaps have a bare-minimum repo to share?

---

<div class="post-metadata">

**Author:** ![Jamal\_B](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@Jamal\_B](https://forum.ansible.com/u/Jamal_B)\
**Post date:** [December 8, 2014, 2:03pm UTC](https://forum.ansible.com/t/role-dependency-not-being-executed/16980/3 "2014-12-08T14:03:44Z")

</div>

Here you go.

[https://github.com/jmal98/ansible-role-dep-example](https://github.com/jmal98/ansible-role-dep-example)

My test env:

root@01e437db9a4c:/role-execution# ansible --version  
ansible 1.7.2

root@01e437db9a4c:/role-execution# export GROUP=compA  
root@01e437db9a4c:/role-execution# ansible-playbook site.yml -c local

PLAY [all] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1]

TASK: [core | Do some common work] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1] =\> {  
“msg”: “Did some common work.”  
}

TASK: [app-common | Do some app-common work] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1] =\> {  
“msg”: “Did some app-common work.”  
}

TASK: [app-compA | Do some app-compA work] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1] =\> {  
“msg”: “Did some app-compA work.”  
}

TASK: [app-compB | Do some app-compB work] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [127.0.0.1]

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
127.0.0.1 : ok=4 changed=0 unreachable=0 failed=0

root@01e437db9a4c:/role-execution# export GROUP=compB  
root@01e437db9a4c:/role-execution# ansible-playbook site.yml -c local

PLAY [all] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1]

TASK: [core | Do some common work] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1] =\> {  
“msg”: “Did some common work.”  
}

TASK: [app-common | Do some app-common work] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [127.0.0.1]

TASK: [app-compA | Do some app-compA work] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [127.0.0.1]

TASK: [app-compB | Do some app-compB work] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1] =\> {  
“msg”: “Did some app-compB work.”  
}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
127.0.0.1 : ok=3 changed=0 unreachable=0 failed=0

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [December 8, 2014, 4:47pm UTC](https://forum.ansible.com/t/role-dependency-not-being-executed/16980/4 "2014-12-08T16:47:25Z")

</div>

Hi Jamal,

We actually have an open issue for this currently: [https://github.com/ansible/ansible/issues/9292](https://github.com/ansible/ansible/issues/9292). For now the work-around is to avoid the “diamond” pattern for roles, where the dependent roles with multiple parents use conditionals or tags.

Thanks!

---

<div class="post-metadata">

**Author:** ![Jamal\_B](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@Jamal\_B](https://forum.ansible.com/u/Jamal_B)\
**Post date:** [December 8, 2014, 6:08pm UTC](https://forum.ansible.com/t/role-dependency-not-being-executed/16980/5 "2014-12-08T18:08:13Z")

</div>

Ok.

Thanks

---

<div class="post-metadata">

**Author:** ![Jamal\_B](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@Jamal\_B](https://forum.ansible.com/u/Jamal_B)\
**Post date:** [December 9, 2014, 10:03pm UTC](https://forum.ansible.com/t/role-dependency-not-being-executed/16980/6 "2014-12-09T22:03:44Z")

</div>

Is it possible to use multiple conditions to activate a role?

e.g.)

- { role: app-compA, when: group== ‘compA’ or group== ‘compB’ }

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [December 9, 2014, 11:25pm UTC](https://forum.ansible.com/t/role-dependency-not-being-executed/16980/7 "2014-12-09T23:25:13Z")

</div>

It should, yes. I just tested in your sample repo -- removing the  
dependencies for compA and compB and then adding a new role for  
app-common:

- { role: app-common, when: group == 'compA' or group == 'compB' }

Worked as I expected; app-common was run when GROUP was either compA  
or compB but was skipped for other values of GROUP.

-Toshio

---

<div class="post-metadata">

**Author:** ![Jamal\_B](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@Jamal\_B](https://forum.ansible.com/u/Jamal_B)\
**Post date:** [December 10, 2014, 2:33pm UTC](https://forum.ansible.com/t/role-dependency-not-being-executed/16980/8 "2014-12-10T14:33:10Z")

</div>

Yeah, I realized that I could try it shortly after firing off this email.

Thanks
