I am working on one of the case in which i need to copy the auth file and hosts files from one server to other.
This can be done with normal copy acion of ansible, but i need to do it using the for loop. The “list” file in below mentioned for loop has the list of ip’s of servers.
It will fetch the first ip and then perform the below task of scp and ssh. then it will proceed with the other things.
Consider i have source server -A, on which my ansible is installed. We will run this command on another host server - B.
the “list” file has the information about the server ip’s of server C.
expected result - from ansible ,our playbook will run on host server i.e. B, and the command should perform the task on the mentioned server in list file i.e. server C.
There is no direct connectivity between A and C.
Please suggest your thoughts
details of list file -
12.82.240.174
12.82.240.166
for i in cat /tmp/list
do
echo $i
scp HLC_auth $i:.ssh/authorized_keys
scp known_hosts.LLC $i:.ssh/known_hosts
ssh $i “rm -rf .ssh/id_dsa*”
ssh $i “ssh-keygen -d”
done