Like I understand the documentation about variable precedence, variable defined in host_vars can override vars in roles default.
I have the following playbook:
---
- hosts: myhosts
gather_facts: false
pre_tasks:
- debug:
msg: "{{ test_role_vars }}"
roles:
- test-role
the default of the role is:
test_role_vars: default
The host_vars looks like:
---
test_role_vars: from host
When I call the playbook, I have the following output:
TASK [debug] ***************************************************************************************************************
task path: /home/sparsick/dev/workspace/ansible-roles-default-vs-host-vars/playbook.yml:5
ok: [tuxedo-os] => {
"msg": "from host"
}
TASK [test-role : debug] ***************************************************************************************************
task path: /home/sparsick/dev/workspace/ansible-roles-default-vs-host-vars/roles/test-role/tasks/main.yml:4
ok: [tuxedo-os] => {
"msg": "default"
}
PLAY RECAP *****************************************************************************************************************
tuxedo-os
But my expectation is that also the role debug should print “from host”.
What is wrong?
The whole sample project can be found here