I want to create similar mapping as in /etc/hosts , but local to use in Ansible, so that all the hostnames are independent of DNS or /etc/hosts and can be stored directly inside VCS.
The motivation for this, usage of hostnames inside playbooks and cli, but using IPs(only if defined) for connections.
Currently I’m using kludgy inventory group for each host like this:
[host1]
192.168.0.1
[host2]
192.168.0.2:4400 host_var=hello
[host3]
192.168.0.3 other_var=world
[host_group:children]
host1
host2
host3
I wonder, it there a better way to do this?
It would be nice to be able to do this:
[host_group]
host1=192.168.0.1
host2=192.168.0.2:4400 host_var=hello
host3=192.168.0.3 other_var=world
If IP is assigned to host, then it’s made available through ‘inventory_ip’, similar to ‘inventory_hostname’. And Ansible should use the defined IP internally for creating connections to hosts.
Regards,
–janis