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

627 views
Skip to first unread message

rell...@gmail.com

unread,
Jan 17, 2016, 9:39:10 PM1/17/16
to Ansible Project
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

Brian Coca

unread,
Jan 18, 2016, 8:31:45 PM1/18/16
to Ansible Project
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.



--
Brian Coca

rell...@gmail.com

unread,
Jan 18, 2016, 11:42:34 PM1/18/16
to Ansible Project
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. 

Brian Coca

unread,
Jan 19, 2016, 10:33:45 AM1/19/16
to Ansible Project
tasks still execute in order, so 'anywhere prior' if you want to split hairs.




--
Brian Coca

Asif Nataliya

unread,
Apr 29, 2016, 9:42:54 AM4/29/16
to Ansible Project
Exactly the same problem I am also facing. Could you please share that how did you resolve this issue?

rell...@gmail.com

unread,
May 18, 2016, 11:13:48 PM5/18/16
to Ansible Project
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. 
Reply all
Reply to author
Forward
0 new messages