# /etc/hosts substitute for dynamic hosts

**URL:** <https://forum.ansible.com/t/etc-hosts-substitute-for-dynamic-hosts/14397>\
**Category:** Ansible Project\
**Created:** [January 21, 2014, 11:41pm UTC](https://forum.ansible.com/t/etc-hosts-substitute-for-dynamic-hosts/14397 "2014-01-21T23:41:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kesten\_Broughton2](https://avatars.discourse-cdn.com/v4/letter/k/ecc23a/32.png) [@Kesten\_Broughton2](https://forum.ansible.com/u/Kesten_Broughton2)\
**Post date:** [January 21, 2014, 11:41pm UTC](https://forum.ansible.com/t/etc-hosts-substitute-for-dynamic-hosts/14397/1 "2014-01-21T23:41:06Z")

</div>

Is there a standard way of supplying the hosts to ip mapping without  
relying on /etc/hosts?

My typical ansible-playbook procedure is

1. Create a vm  
2. Add ip fqdn hostname line to /etc/hosts  
3. Add hostname to groups in ansible\_hosts file

I would prefer to keep dynamically generated hosts separate from /etc/hosts

something like

ansible-playbook -i hosts -z etc\_hosts site.yml

where -z specifies the host-ip mapping file.

I am aware of the ability to have in hosts

[my\_group]  
host\_vm\_name ansible-ssh-host=10.1.12.1

But again, dynamically managing this would be a bit tricky compared to just  
generating an ansible\_hosts (hosts) file and an etc-hosts file separately,  
in my mind. Better separation of concerns to have architectural grouping  
in one place and ip mapping in another in my opinion.

Is there an ansible way to achieve something like this?

kesten

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [January 21, 2014, 11:44pm UTC](https://forum.ansible.com/t/etc-hosts-substitute-for-dynamic-hosts/14397/2 "2014-01-21T23:44:04Z")

</div>

The most standard way is DNS 🙂

Also in the above, you have “ansible-ssh-host” where it is really “ansible\_ssh\_host”

When you say

“But again, dynamically managing this would be a bit tricky compared to just generating an ansible\_hosts (hosts) file and an etc-hosts file separately, in my mind”

It sounds like you are doing dynamic things, so I’d suggest reading this and not have a file at all:

[http://docs.ansible.com/intro\_dynamic\_inventory.html](http://docs.ansible.com/intro_dynamic_inventory.html)
