Target name question

I have a list of servers to migrate, say:

old_server_1
old_server_2

and a list of new servers, say:

new_server_1
new_server_2

Because the names of the new servers are still undecided I want to use the old names in the hosts file, keep a server’s new name as a variable in host_vars (newname) and then convert the old to new dynamically before comms start.

Now, Ansible deploy to the names in the inventory file, but is there a way in which internally I can substitute, say old_server_1.newname for new_server_1?

Thanks

I’m not sure I understand this particular question.

When you say hosts file, is this about restructuring your ansible inventory file?

I’m not sure I understand this particular question.

When you say hosts file, is this about restructuring your ansible inventory file?

Yes. Let me try to explain it better.

I guess what I am asking is if whether Ansible has an internal variable that is set to the current host being processed, which can be set in the plays so that another different host gets processed instead.

“which can be set in the plays so that another different host gets processed instead.”

If ansible_ssh_host is set as a variable name on the host, either in the INI file or hostvars/hostname, the address given for ansible_ssh_host is used to contact the system rather than the verbatim name of the host, basically, it becomes an alias. Similarly, ansible_ssh_port is also a thing.

“which can be set in the plays so that another different host gets processed instead.”

If ansible_ssh_host is set as a variable name on the host, either in the INI file or hostvars/hostname, the address given for ansible_ssh_host is used to contact the system rather than the verbatim name of the host, basically, it becomes an alias. Similarly, ansible_ssh_port is also a thing.

Thank you kindly. That works really well.

Is the verbatim name still available (in another variable?) after assigning a value to ansible_ssh_host ?

Excerpts from Tiglath's message of 2014-08-12 23:08:48 -0400:

Is the verbatim name still available (in another variable?) after assigning
a value to ansible_ssh_host ?

'inventory_hostname' should always refer to the primary name in the
hosts file.