/etc/hosts substitute for dynamic hosts

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

The most standard way is DNS :slight_smile:

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