# Changing variable depending on the host within a role

**URL:** <https://forum.ansible.com/t/changing-variable-depending-on-the-host-within-a-role/23072>\
**Category:** Ansible Project\
**Created:** [November 22, 2016, 10:14am UTC](https://forum.ansible.com/t/changing-variable-depending-on-the-host-within-a-role/23072 "2016-11-22T10:14:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adnan\_Arab](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@Adnan\_Arab](https://forum.ansible.com/u/Adnan_Arab)\
**Post date:** [November 22, 2016, 10:14am UTC](https://forum.ansible.com/t/changing-variable-depending-on-the-host-within-a-role/23072/1 "2016-11-22T10:14:36Z")

</div>

Hi,

I want to be able to change the value of a variable depending on a host.

What I tried was roles/x/vars/host\_vars//main.yml but this does not seem to work.

Could you please let me know how I can change a variable depending on a host within a role?

Thanks

---

<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:** [November 22, 2016, 6:02pm UTC](https://forum.ansible.com/t/changing-variable-depending-on-the-host-within-a-role/23072/2 "2016-11-22T18:02:37Z")

</div>

host\_vars is a feature of the top level, not in the roles

[https://docs.ansible.com/ansible/playbooks\_best\_practices.html#directory-layout](https://docs.ansible.com/ansible/playbooks_best_practices.html#directory-layout)
