This one was easy, first create a file (hosts_ip.txt) with the IP of each server to get its /etc/hosts:

Generate a private/public pair key and add the public one in authorized_keys of each server :

Copy the private keys to a common directory, in this case “/home/mortiz/get_hosts/pass_<server_ip>” and with some shell the magic happens:

That’s it.