# How to use IPs defined in hosts file in playbooks?

**URL:** <https://forum.ansible.com/t/how-to-use-ips-defined-in-hosts-file-in-playbooks/17355>\
**Category:** Ansible Project\
**Created:** [January 22, 2015, 4:23pm UTC](https://forum.ansible.com/t/how-to-use-ips-defined-in-hosts-file-in-playbooks/17355 "2015-01-22T16:23:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Hirsch](https://avatars.discourse-cdn.com/v4/letter/t/eb8c5e/32.png) [@Thomas\_Hirsch](https://forum.ansible.com/u/Thomas_Hirsch)\
**Post date:** [January 22, 2015, 4:23pm UTC](https://forum.ansible.com/t/how-to-use-ips-defined-in-hosts-file-in-playbooks/17355/1 "2015-01-22T16:23:52Z")

</div>

Hello,  
when configuring a load balancer for example, with a templated configuration file, how would I go about inserting IP addresses from my inventory file?

I realize that I might not be understanding completely how roles, playbooks, and the inventory file (and variable files) are supposed to divide responsibilities among them, because I generally have a one-to-one-to-many mapping of hosts to playbooks to roles.

For example:

File ‘hosts’ -----

[db-machine]  
\<IP #1\>

[webserver]  
\<IP #2\>

---

<div class="post-metadata">

**Author:** ![t.hirsch](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@t.hirsch](https://forum.ansible.com/u/t.hirsch)\
**Post date:** [January 22, 2015, 4:39pm UTC](https://forum.ansible.com/t/how-to-use-ips-defined-in-hosts-file-in-playbooks/17355/2 "2015-01-22T16:39:39Z")

</div>

Edit:  
I just noticed this example is kind of bad because, I would probably be using a different (i.e. not the public) IP address when configuring a load balancer.  
I guess it makes sense to manually assign IP addresses to every host in the private network, and have that in a variables file, which in turn I could include in all the roles/tasks that need those IPs. Does that make sense?
