Naming hosts in ansible inventory

The workaround I've been using is to create a separate DNS (or
/etc/hosts) entry for the tunnels. From my understanding since I
implemented it there has been some work done with host aliases/labels,
but I haven't had enough time to explore those.

With the DNS approach make sure that the *first* entry in your ansible
hosts file has the port number set correctly. The port number of all
following entries will be ignored. So for example you can have a
hosts file like this:

tunnel021.local:62021
tunnel022.local:62022

[foo]
tunnel021.local
tunnel022.local

The entries in group foo will use the previously defined ports for
those hosts.

Thanks,

With the DNS approach make sure that the first entry in your ansible
hosts file has the port number set correctly. The port number of all
following entries will be ignored.

Then, if I understand the above well, my use case does require keeping an up-to-date /etc/hosts because ansible will ignore specifying different ports for the same IP (127.0.0.1) in the inventory file?

From my understanding since I
implemented it there has been some work done with host aliases/labels,

Anybody has used a different approach with success?

Thanks

ansible's inventory records are essentially strings.

It does respect a variable called ansible_ssh_port, which when set on any inventory record, will cause it to speak to exactly that port.

The port can also be specified like:

hostname:12345

although you cannot have duplicate hostnames in the inventory file (yet) because the port is not stored as part of the name.

If it were, some people would find that confusing because "hostname*" would be needed to match "hostname:12345"

I think the ideal proposal would be something like this

some_identifier:12345 alias_for=foosball.example.org
other_identifier:12346 alias_for=foosball.example.org

but the connection code doesn't allow keeping a host specific address separate from the name in inventory right now. Patches would be considered for 0.7