# ansible hosts and hosts\_vars usage

**URL:** <https://forum.ansible.com/t/ansible-hosts-and-hosts-vars-usage/21034>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [March 31, 2016, 3:07pm UTC](https://forum.ansible.com/t/ansible-hosts-and-hosts-vars-usage/21034 "2016-03-31T15:07:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_Hanstra](https://avatars.discourse-cdn.com/v4/letter/t/4491bb/32.png) [@Tom\_Hanstra](https://forum.ansible.com/u/Tom_Hanstra)\
**Post date:** [March 31, 2016, 3:07pm UTC](https://forum.ansible.com/t/ansible-hosts-and-hosts-vars-usage/21034/1 "2016-03-31T15:07:13Z")

</div>

Can someone give me a more complete example of how to tie together ansible hosts file and the hosts\_var directory?

My ansible hosts file is getting out of hand and I want to break it up better. I use variables for various pieces of info. Currently my hosts file has sections like this:

[myserver]  
myserver.my.domain

[myserver:vars]  
host=myserver.my.domain  
tagName=myserver  
tagOwner=thanstra  
tagBackup=True

And then I can later use the variables which are set there:

- name: Tag the instance Name  
command: aws ec2 create-tags --resources {{ ansible\_ec2\_instance\_id }} --tags Key=Name,Value={{ tagName }}

I’d like to break this up to build files in hosts\_var with those various vars in separate files for each server. But I’m having trouble figuring out the right syntax, naming conventions, etc for what needs to go in ansible hosts file and host\_vars/[connected file].

Can someone give me clear information on what files I need and what the syntax of the files should look like?

Thank you!

---

<div class="post-metadata">

**Author:** ![ishan\_jain](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@ishan\_jain](https://forum.ansible.com/u/ishan_jain)\
**Post date:** [April 1, 2016, 9:20am UTC](https://forum.ansible.com/t/ansible-hosts-and-hosts-vars-usage/21034/2 "2016-04-01T09:20:38Z")

</div>

The information you are looking for in nicely documented in the Ansible docs - [http://docs.ansible.com/ansible/intro\_inventory.html](http://docs.ansible.com/ansible/intro_inventory.html)

You need to create forlders named exactly as ‘group\_vars’ and ‘host\_vars’ right beside your host file and in them you create files with the same name as your group or host (optionaly with a .yaml extension).
