# Overridden variable leaking out of dependency declared in role meta?

**URL:** <https://forum.ansible.com/t/overridden-variable-leaking-out-of-dependency-declared-in-role-meta/29576>\
**Category:** Ansible Project\
**Created:** [January 30, 2019, 9:08pm UTC](https://forum.ansible.com/t/overridden-variable-leaking-out-of-dependency-declared-in-role-meta/29576 "2019-01-30T21:08:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![moreati](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/moreati/32/5303_2.png) [@moreati](https://forum.ansible.com/u/moreati)\
**Post date:** [January 30, 2019, 9:08pm UTC](https://forum.ansible.com/t/overridden-variable-leaking-out-of-dependency-declared-in-role-meta/29576/1 "2019-01-30T21:08:11Z")

</div>

I have 2 roles (r1 and r2), r2 depends on r1 and the dependency overrides a variable (x). I would expect the overridden value to only apply while r1 is run as a dependency. However the overridden value gets applied throughout the entire play.

If r1 is run in it’s only play, without r2, then I get the value from group\_vars/ as I expect.

Below is a minimal reproduction. Have I found a bug, or am I misunderstanding how Ansible variables are scoped?

With thanks, Alex

# group\_vars/g1

x: set by group\_vars

# roles/r1/tasks/main.yml

- debug:  
var: x

# roles/r2/meta/main.yml

dependencies:

- role: r1  
vars:  
x: overridden by dependency

# roles/r2/tasks/main.yml

- debug:  
var: x

# inventory

g1:  
hosts:  
localhost:

# playbook.yml

- hosts: g1  
connection: local  
roles:
- r1
- r2

# ansible.cfg

[defaults]  
stdout\_callback=yaml

:/tmp/test [v]$ ansible-playbook -i inventory playbook.yml

PLAY [Play that includes dependency] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost]

TASK [r1 : debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\>  
x: overridden by dependency

TASK [r1 : debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\>  
x: overridden by dependency

TASK [r2 : debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\>  
x: overridden by dependency

PLAY [Play that excludes dependency] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost]

TASK [r1 : debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\>  
x: set by group\_vars

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
localhost : ok=6 changed=0 unreachable=0 failed=0

:/tmp/test [v]$ ansible-playbook --version  
ansible-playbook 2.7.6  
config file = /tmp/test/ansible.cfg  
configured module search path = [u’/home/alex/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]  
ansible python module location = /tmp/v/local/lib/python2.7/site-packages/ansible  
executable location = /tmp/v/bin/ansible-playbook  
python version = 2.7.15rc1 (default, Nov 12 2018, 14:31:15) [GCC 7.3.0]
