defaults vs vars precedence in dependent roles

25 views
Skip to first unread message

Andrew Martin

unread,
Aug 4, 2015, 4:45:04 PM8/4/15
to Ansible Project
Hello,

I have structured my roles such that redistributable roles, such as a role for installing mariadb, define as many of their variables in defaults/main.yml as possible. This way, any role that includes that redistributable role in its meta/main.yml can override that variable with a custom value by setting it in its vars/main.yml:

roles/mariadb/defaults/main.yml:
---
mysql_password: "password1234"

roles/myserver/meta/main.yml:
---
dependencies:
  - { role: mariadb }

roles/myserver/vars/main.yml:
---
mysql_password: "secretpassword"

Thus, myserver should have mysql_password set to "secretpassword" when it is run. This has worked well until recently, when it stopped working completely (possibly when I upgraded to 1.9.x). Now, it seems that a custom value defined in vars/main.yml does not override a default value in a meta role. I prefer overriding the variables in vars/main.yml rather than needing to override them in meta/main.yml because that can become a long, messy list.

Has variable precedence behavior changed recently, or can anyone explain why this has stopped working?

Thanks,

Andrew Martin
Reply all
Reply to author
Forward
0 new messages