same variable on different roles

Hi

I want to ask what is expected behaviour on variables. So for example I have two roles and on vars i have same variable name like tmp_dir but pointing on different directories

role1/vars/
role2/vars/

and what happens if i create a yml file contains

roles:

  • role1
  • role2

I was thinking while running role1 tmp_dir value will be used from role1/vars/main.yml and when running role2 tmp_dir variable is taken from role2/vars/main.yml. But it seems either something has changed with 2.8 or I was wrong from the beginning.

Also what should i do to realize my goal (using different variable value for same variable name on different role)

Regards.

It's woking great for me.

$ ansible --version
ansible 2.8.0

$ more roles/role{1,2}/{tasks,vars}/main.yml | cat
::::::::::::::
roles/role1/tasks/main.yml
::::::::::::::

Hi,

Actually that is what I expect but don’t know what happened but now variables seems to be all combined so I can’t use same variable name to contain different values on different roles.

Regards.

You are probably also setting the variables other places?
Since variables in Ansible are global they are overwritten according to this precedence list
https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable