change the hostname for multiple servers

HI Team,
How to replace hostname in multiple servers in /etc/hosts file
steps to be taken care
i will pass ip's and servers names with a list file
Example : 
10.10.10.10  test1 
10.10.10.10 test2

original server name are 
abcd1
abcd2
my requirement is to login server with first ip and should change name from abcd1 to test1 in /etc/hosts file
and 

login server with second ip  from list and should change name from abcd2 to test2 in /etc/hosts file


Can anyone help me with this


Regards,

Ankit

  • post-author-pic
    John M
    10-31-2018

    Ankit, I would recommend a look at Terry Cox's Ansible Quickstart lesson and then use Ansible to make the changes to the /etc/hosts. You may also want to be sure you align the names of the hosts in the hosts lookup file with the actual uname of the servers. If you don't want to use Ansible, then a sed script run through a remote shell may suffice. 

  • post-author-pic
    Ankit S
    11-02-2018

    By any chance i can get sed script. 
    I am not able to pass the variables in arguments can anyone help me on this

Looking For Team Training?

Learn More