# How can we access the variables defined in host\_vars/\* files into playbook

**URL:** <https://forum.ansible.com/t/how-can-we-access-the-variables-defined-in-host-vars-files-into-playbook/26320>\
**Category:** Ansible Project\
**Created:** [December 18, 2017, 5:33pm UTC](https://forum.ansible.com/t/how-can-we-access-the-variables-defined-in-host-vars-files-into-playbook/26320 "2017-12-18T17:33:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chandramohan\_Reddy](https://avatars.discourse-cdn.com/v4/letter/c/ed655f/32.png) [@Chandramohan\_Reddy](https://forum.ansible.com/u/Chandramohan_Reddy)\
**Post date:** [December 18, 2017, 5:33pm UTC](https://forum.ansible.com/t/how-can-we-access-the-variables-defined-in-host-vars-files-into-playbook/26320/1 "2017-12-18T17:33:42Z")

</div>

Hey there,

I am facing below error when i am trying to access the variables defined in host\_vars/ansible.com.

I have defined variable name in host vars file called “[ansible.com](http://ansible.com)” like

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [December 18, 2017, 9:17pm UTC](https://forum.ansible.com/t/how-can-we-access-the-variables-defined-in-host-vars-files-into-playbook/26320/2 "2017-12-18T21:17:49Z")

</div>

Your play is targeting 'localhost', but you defined the variable for  
the 'ansible.com' host, either move the file to 'localhost' to match  
the host name or use the hostvars[\<hostname\>][\<varname\>] method to  
access variables defined in other hosts.
