# Target name question

**URL:** <https://forum.ansible.com/t/target-name-question/15915>\
**Category:** Ansible Project\
**Created:** [August 11, 2014, 9:18pm UTC](https://forum.ansible.com/t/target-name-question/15915 "2014-08-11T21:18:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tiglath](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@Tiglath](https://forum.ansible.com/u/Tiglath)\
**Post date:** [August 11, 2014, 9:18pm UTC](https://forum.ansible.com/t/target-name-question/15915/1 "2014-08-11T21:18:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 11, 2014, 10:02pm UTC](https://forum.ansible.com/t/target-name-question/15915/2 "2014-08-11T22:02:27Z")

</div>

I’m not sure I understand this particular question.

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

---

<div class="post-metadata">

**Author:** ![Tiglath](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@Tiglath](https://forum.ansible.com/u/Tiglath)\
**Post date:** [August 12, 2014, 9:47pm UTC](https://forum.ansible.com/t/target-name-question/15915/3 "2014-08-12T21:47:03Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 12, 2014, 10:22pm UTC](https://forum.ansible.com/t/target-name-question/15915/4 "2014-08-12T22:22:17Z")

</div>

“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.

---

<div class="post-metadata">

**Author:** ![Tiglath](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@Tiglath](https://forum.ansible.com/u/Tiglath)\
**Post date:** [August 13, 2014, 3:08am UTC](https://forum.ansible.com/t/target-name-question/15915/5 "2014-08-13T03:08:48Z")

</div>

> “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 ?

---

<div class="post-metadata">

**Author:** ![C\_Morgan\_Hamill](https://avatars.discourse-cdn.com/v4/letter/c/ebca7d/32.png) [@C\_Morgan\_Hamill](https://forum.ansible.com/u/C_Morgan_Hamill)\
**Post date:** [August 13, 2014, 2:44pm UTC](https://forum.ansible.com/t/target-name-question/15915/6 "2014-08-13T14:44:06Z")

</div>

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.
