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