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 :  test1 test2

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

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



  • post-author-pic
    John M

    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

    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