ansible hosts and hosts_vars usage

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!

The information you are looking for in nicely documented in the Ansible docs - 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).