# variable precedence seems not working as intended

**URL:** <https://forum.ansible.com/t/variable-precedence-seems-not-working-as-intended/16717>\
**Category:** Ansible Project\
**Created:** [November 7, 2014, 12:35pm UTC](https://forum.ansible.com/t/variable-precedence-seems-not-working-as-intended/16717 "2014-11-07T12:35:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Piotr\_Goslawski](https://avatars.discourse-cdn.com/v4/letter/p/46a35a/32.png) [@Piotr\_Goslawski](https://forum.ansible.com/u/Piotr_Goslawski)\
**Post date:** [November 7, 2014, 12:35pm UTC](https://forum.ansible.com/t/variable-precedence-seems-not-working-as-intended/16717/1 "2014-11-07T12:35:19Z")

</div>

From [http://docs.ansible.com/playbooks\_variables.html#variable-precedence-where-should-i-put-a-variable](http://docs.ansible.com/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable)

> If multiple variables of the same name are defined in different places, they win in a certain order, which is:

> ```auto
> * -e variables always win
> * then comes "most everything else"
> * then comes variables defined in inventory
> * then comes facts discovered about a system
> * then "role defaults", which are the most "defaulty" and lose in priority to everything.
> 
> ```

But when I define a variable both in play and in the inventory, the value from the inventory is used.

Bug / docs not up to date / I’m missing something?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [November 7, 2014, 7:29pm UTC](https://forum.ansible.com/t/variable-precedence-seems-not-working-as-intended/16717/2 "2014-11-07T19:29:56Z")

</div>

what version of ansible? I just tested this and play vars override inventory (the one exception is ansible\_ vars which are normally used for a particular host’s connection info).

---

<div class="post-metadata">

**Author:** ![Piotr\_Goslawski](https://avatars.discourse-cdn.com/v4/letter/p/46a35a/32.png) [@Piotr\_Goslawski](https://forum.ansible.com/u/Piotr_Goslawski)\
**Post date:** [November 8, 2014, 10:26pm UTC](https://forum.ansible.com/t/variable-precedence-seems-not-working-as-intended/16717/3 "2014-11-08T22:26:41Z")

</div>

version 1.7.2  
It was indeed ansible\_ssh\_user variable. I needed to switch user for one task, but sudo would break ssh agent forwarding.  
So this is how it’s supposed to be? Would be nice if docs said something about it…

W dniu piątek, 7 listopada 2014 20:29:59 UTC+1 użytkownik Brian Coca napisał:
