# One question about the default variables of dependency roles override in ansible 2.0

**URL:** <https://forum.ansible.com/t/one-question-about-the-default-variables-of-dependency-roles-override-in-ansible-2-0/20246>\
**Category:** Ansible Project\
**Created:** [January 18, 2016, 2:39am UTC](https://forum.ansible.com/t/one-question-about-the-default-variables-of-dependency-roles-override-in-ansible-2-0/20246 "2016-01-18T02:39:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rella.guo](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@rella.guo](https://forum.ansible.com/u/rella.guo)\
**Post date:** [January 18, 2016, 2:39am UTC](https://forum.ansible.com/t/one-question-about-the-default-variables-of-dependency-roles-override-in-ansible-2-0/20246/1 "2016-01-18T02:39:10Z")

</div>

Hi all,

Upgrade to ansible 2.0, my playbook activities changed. I have a question about default variables of dependency roles.

I have a role A which depends on role B. Role B is defined in meta/main.yml of role A.  
Actually, I want to override one default variable “var\_a” of Role B. So I define “var\_a” again in default/main.yml of Role A. By this way I override “var\_a” with ansible 1.9. But when I use ansible 2.0, “var\_a” could not be overridden again.

I am not sure whether it is a bug of ansible 2.0 or it is the enhancement of ansible 2.0.

Which is the best way to override the default variables of dependency role which is defined in meta/main.yml?

Thank you very much!

– Rella

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 19, 2016, 1:31am UTC](https://forum.ansible.com/t/one-question-about-the-default-variables-of-dependency-roles-override-in-ansible-2-0/20246/2 "2016-01-19T01:31:37Z")

</div>

In 2.0 we defined this behavior (it was undefined and changed in  
previous versions), roles will prefer their own defaults, you can  
override these by setting the var anywhere else except in the defaults  
of another role.

---

<div class="post-metadata">

**Author:** ![rella.guo](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@rella.guo](https://forum.ansible.com/u/rella.guo)\
**Post date:** [January 19, 2016, 4:42am UTC](https://forum.ansible.com/t/one-question-about-the-default-variables-of-dependency-roles-override-in-ansible-2-0/20246/3 "2016-01-19T04:42:34Z")

</div>

Actually, I did test by setting the var of role B in vars folder of role A. Role A defines role B in meta. Override is failed. Role B would be executed before role A. So role A cannot override any vars of role B. If I want override vars of role B, I must set vars in playbook or inventory, right?  
So I suppose “anywhere” except in the defaults of another role you said is not really exact.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 19, 2016, 3:33pm UTC](https://forum.ansible.com/t/one-question-about-the-default-variables-of-dependency-roles-override-in-ansible-2-0/20246/4 "2016-01-19T15:33:38Z")

</div>

tasks still execute in order, so 'anywhere prior' if you want to split hairs.

---

<div class="post-metadata">

**Author:** ![Asif\_Nataliya](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@Asif\_Nataliya](https://forum.ansible.com/u/Asif_Nataliya)\
**Post date:** [April 29, 2016, 6:12am UTC](https://forum.ansible.com/t/one-question-about-the-default-variables-of-dependency-roles-override-in-ansible-2-0/20246/5 "2016-04-29T06:12:31Z")

</div>

Exactly the same problem I am also facing. Could you please share that how did you resolve this issue?

---

<div class="post-metadata">

**Author:** ![rella.guo](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@rella.guo](https://forum.ansible.com/u/rella.guo)\
**Post date:** [May 19, 2016, 3:13am UTC](https://forum.ansible.com/t/one-question-about-the-default-variables-of-dependency-roles-override-in-ansible-2-0/20246/6 "2016-05-19T03:13:48Z")

</div>

If role A depends on role B and you want to override the default var of role B by role A, you can define this var in vars/main.yml of role A. I use this solution in ansible 2.0.2.0.
