# Extra var does not override host\_vars when passing to include

**URL:** <https://forum.ansible.com/t/extra-var-does-not-override-host-vars-when-passing-to-include/22797>\
**Category:** Ansible Project\
**Created:** [October 15, 2016, 10:40am UTC](https://forum.ansible.com/t/extra-var-does-not-override-host-vars-when-passing-to-include/22797 "2016-10-15T10:40:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Do\_Hoang\_Khiem](https://avatars.discourse-cdn.com/v4/letter/d/3d9bf3/32.png) [@Do\_Hoang\_Khiem](https://forum.ansible.com/u/Do_Hoang_Khiem)\
**Post date:** [October 15, 2016, 10:40am UTC](https://forum.ansible.com/t/extra-var-does-not-override-host-vars-when-passing-to-include/22797/1 "2016-10-15T10:40:57Z")

</div>

Enter code here…  
When I pass a variable to include: statement, using value from extra vars, the value inside the included task file is still the value from host\_vars, not extra vars (while extra vars are considered as highest precedence)

Here’e an example

**main.yml**

`

- name: test extra var

hosts: localhost  
connection: local

gather\_facts: no

tasks:

- include: task.yml internal\_var={{my\_var}}

`

**task.yml**

`

- name: print internal\_var

debug: msg=“hello, {{internal\_var}}”

`

**inventory**

`  
[local]

localhost ansible\_connection=local

`

**host\_vars/localhost**

`  
my\_var: I am from host\_vars

`

then test

`

LAZ-VN-L-M-1034:test user$ ansible-playbook -i inventory main.yml -e ‘my\_var=testtest’

PLAY [pulling Avanan Registration Management UI from git remote repository] \*\*\*

TASK: [print internal\_var] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“msg”: “hello, I am from host\_vars”  
}

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

`

It still takes value from host\_vars/localhost even though extra var is passed.

Is it an error? Ansible version is 1.9.4

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 15, 2016, 10:57am UTC](https://forum.ansible.com/t/extra-var-does-not-override-host-vars-when-passing-to-include/22797/2 "2016-10-15T10:57:55Z")

</div>

I would say it's a bug, it works in Ansible 2.1.2

TASK [print internal\_var]
