Extra var does not override host_vars when passing to include

24 views
Skip to first unread message

Do Hoang Khiem

unread,
Oct 15, 2016, 6:40:57 AM10/15/16
to Ansible Project
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


Kai Stian Olstad

unread,
Oct 15, 2016, 6:58:29 AM10/15/16
to ansible...@googlegroups.com
On 15. okt. 2016 12:40, Do Hoang Khiem wrote:
> TASK: [print internal_var]
> ****************************************************
> ok: [localhost] => {
> "msg": "hello, I am from host_vars"
> }
>
>
> It still takes value from host_vars/localhost even though extra var is
> passed.
>
>
> Is it an error? Ansible version is 1.9.4

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

TASK [print internal_var]
******************************************************
ok: [localhost] => {
"msg": "hello, testtest"
}

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages