Question:
I am new to Ansible. I am able to test it and its working fine with my test requirment. For making connection between management node and the client node I am using already created ssh key pair. How can I use another node with different SSH key pair? For reference I am considering 3 ec2-instance with different key pairs.
Answer:
Good news- in a basic use case, this is fairly easy. Simply use the ansible_ssh_private_key_file
parameter in your Ansible inventory.
Here are some examples purloined from my personal file:
1 2 3 4 5 6 7 8 9 10 11 12 |
$ cat hosts.ini [server1] 54.1.2.3 ansible_ssh_private_key_file=~/.ssh/server1.pem [testservers] ec2-54-2-3-4.compute-1.amazonaws.com ansible_ssh_private_key_file=~/.ssh/aws-testserver.pem ansible_ssh_user=ubuntu ec2-54-2-3-5.compute-1.amazonaws.com ansible_ssh_private_key_file=~/.ssh/aws-testserver.pem ansible_ssh_user=ubuntu [piwall] 10.0.0.88 ansible_ssh_private_key_file=~/.ssh/raspberrypi.pem ansible_ssh_user=pi |