# Does host\_vars override role default role

**URL:** <https://forum.ansible.com/t/does-host-vars-override-role-default-role/41511>\
**Category:** Get Help\
**Tags:** variables, role, inventory\
**Created:** [April 4, 2025, 8:42am UTC](https://forum.ansible.com/t/does-host-vars-override-role-default-role/41511 "2025-04-04T08:42:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sparsick](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@sparsick](https://forum.ansible.com/u/sparsick)\
**Post date:** [April 4, 2025, 8:42am UTC](https://forum.ansible.com/t/does-host-vars-override-role-default-role/41511/1 "2025-04-04T08:42:38Z")

</div>

Like I understand the documentation about [variable precedence](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html#defining-variables-in-included-files-and-roles), variable defined in host\_vars can override vars in roles default.

I have the following playbook:

```auto
---
- hosts: myhosts
  gather_facts: false
  pre_tasks:
    - debug:
        msg: "{{ test_role_vars }}"
  roles:
   - test-role

```

the default of the role is:

```auto
test_role_vars: default

```

The host\_vars looks like:

```auto
---
test_role_vars: from host

```

When I call the playbook, I have the following output:

```auto

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](https://github.com/sparsick/ansible-roles-default-vs-host-vars)

---

<div class="post-metadata">

**Author:** ![sparsick](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@sparsick](https://forum.ansible.com/u/sparsick)\
**Post date:** [April 4, 2025, 9:44am UTC](https://forum.ansible.com/t/does-host-vars-override-role-default-role/41511/2 "2025-04-04T09:44:22Z")

</div>

Found it. I had a typo. Sorry for the noise
