Target name question

47 views
Skip to first unread message

Tiglath

unread,
Aug 11, 2014, 5:18:05 PM8/11/14
to ansible...@googlegroups.com
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
 
 

Michael DeHaan

unread,
Aug 11, 2014, 6:02:32 PM8/11/14
to ansible...@googlegroups.com
I'm not sure I understand this particular question.

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


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/27dd466e-307a-4f91-ae6d-0a400c9f5b06%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tiglath

unread,
Aug 12, 2014, 5:47:04 PM8/12/14
to ansible...@googlegroups.com

On Monday, August 11, 2014 6:02:32 PM UTC-4, Michael DeHaan wrote:
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.   

Michael DeHaan

unread,
Aug 12, 2014, 6:22:23 PM8/12/14
to ansible...@googlegroups.com
"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.





Tiglath

unread,
Aug 12, 2014, 11:08:48 PM8/12/14
to ansible...@googlegroups.com


On Tuesday, August 12, 2014 6:22:23 PM UTC-4, Michael DeHaan wrote:
"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 ?

C. Morgan Hamill

unread,
Aug 13, 2014, 10:44:10 AM8/13/14
to ansible-project
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.
--
Morgan Hamill
Reply all
Reply to author
Forward
0 new messages