# Var precedence

**URL:** <https://forum.ansible.com/t/var-precedence/12866>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [May 24, 2013, 9:20pm UTC](https://forum.ansible.com/t/var-precedence/12866 "2013-05-24T21:20:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [May 24, 2013, 9:20pm UTC](https://forum.ansible.com/t/var-precedence/12866/1 "2013-05-24T21:20:42Z")

</div>

If you want to overrule variables in roles with variables defined in the playbook (or elsewhere) you might try something like this:

$ cat rolesvar.yml

- hosts: localhost  
gather\_facts: false  
vars:  
foo2: overruled\_rom\_role\_invocation  
roles:
- role: test
- role: test  
foo: $foo2

$ ansible-playbook rolesvar.yml

PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK: [debug msg=default\_from\_role] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost]

TASK: [debug msg=overruled\_rom\_role\_invocation] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost]

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

Serge
